When writing batch scripts or dealing with cmd.exe, we may run into file not found errors from time to time. In cmd.exe, some different errors may be reported when a file/directory/drive cannot be found.

1.

'...' is not recognized as an internal or external command, operable program or batch file.

Error Text
'…' is not recognized as an internal or external command, operable program or batch file.
%ERRORLEVEL%
9009
Examples
%ProgramFiles%\Notepad++\notepad++.exe
RandomCommand
C:\Windows\NonExistent.exe
Notes
This error is reported when the command to be executed does not exist.
If the command is in the form dir1\dir2\file, it implies that dir1\dir2 does exist, but file does not exist in that directory. If dir1\dir2 does not exist, path not found error is reported.

2.1

The system cannot find the path specified.

Error Text
The system cannot find the path specified.
%ERRORLEVEL%
3
Examples
dir1\dir2\file
C:\Window\notepad.exe

2.2

The system cannot find the path specified.

Error Text
The system cannot find the path specified.
Notes
Here, please be noted that if this particular error happens in the I/O redirection part (> C:\nonexistent\file), i.e., the directory containing the file to be redirected to does not exist, then %ERRORLEVEL% won't be touched at all, neither reflects this error, nor reflects the actual exit code returned by the command, but keeping its previous value.
%ERRORLEVEL%
Not Touched, keeping its previous value.
Example
diff > C:\nonexistent\file

3.

The filename, directory name, or volume label syntax is incorrect.

Error Text
The filename, directory name, or volume label syntax is incorrect.
%ERRORLEVEL%
123
Examples
" %ProgramFiles%\Notepad++\notepad++.exe"
'%ProgramFiles%\Notepad++\notepad++.exe'
Notes
When a path contains leading spaces, or is surrounded by single quotes, this error is reported.
Note that paths with trailing spaces are fine.
Note that call commands with leading spaces via cmd /c is fine.

4.

The system cannot find the drive specified.

Error Text
The system cannot find the drive specified.
%ERRORLEVEL%
Not Touched, keeping its previous value.
Examples
Z:
B:\dir

5.1

When commands are prefixed with start, and encounter file/path not found error when executing, %ERRORLEVEL% will always be set to 9059.

The system cannot find the file

Error Text
The system cannot find the file filename.
%ERRORLEVEL%
9059
Examples
start RandomCommand
start dir1\dir2\file
start "" " %ProgramFiles%\Notepad++\notepad++.exe"

5.2

When commands are prefixed with start, and encounter drive not found error when executing, %ERRORLEVEL% will be set to 5, in contrast to not touched when running commands without start prefixed as documented in previous section.

Access is denied.

Error Text
Access is denied.
%ERRORLEVEL%
5
Examples
start B:\dir

6

When commands are prefixed with call or cmd /c, and encounter file/path/drive not found error when executing, %ERRORLEVEL% will always be set to 1.

Execute commands with call or cmd /c prefix

Error Text
The same as when executed without call or cmd /c.
%ERRORLEVEL%
1
Examples
call RandomCommand
call dir1\dir2\file
call " %ProgramFiles%\Notepad++\notepad++.exe"
call B:\dir

cmd /c RandomCommand
cmd /c dir1\dir2\file
cmd /c B:\dir