diff --git a/ShellPkg/Library/UefiShellLib/UefiShellLib.c b/ShellPkg/Library/UefiShellLib/UefiShellLib.c index 0c99e23650..6e0f61130f 100644 --- a/ShellPkg/Library/UefiShellLib/UefiShellLib.c +++ b/ShellPkg/Library/UefiShellLib/UefiShellLib.c @@ -702,8 +702,9 @@ ShellOpenFileByName( } PathCleanUpDirectories (FileNameCopy); if (PathRemoveLastItem (FileNameCopy)) { - ShellCreateDirectory (FileNameCopy, FileHandle); - ShellCloseFile (FileHandle); + if (!EFI_ERROR(ShellCreateDirectory (FileNameCopy, FileHandle))) { + ShellCloseFile (FileHandle); + } } SHELL_FREE_NON_NULL (FileNameCopy); }