[Solved] The System Can Not Find The Path Specified Error in Command Prompt

In this blog, we will see how to solve "The system cannot find the path specified error" in Command Prompt/cmd/command-line interface.
The above error can occur in three ways,
1. Incorrect directory name.
2. Try to compile the non-existing file using the directory (folder) path in Windows.
3. When the values in Registry Editor-HKEY_CURRENT_USER\Software\Microsoft\CommandProcessor\AutoRun are not cleared.

Read Also: [Solved] invalid method declaration; return type required

1. Incorrect directory name



In general, we can change the current working directory to the different paths in the system. To change the working directory, we execute the command cd followed by an absolute or relative path of the directory. The absolute path is the full path of a file or directory from the root directory. The relative path is the partial path related to the current working directory.
When you use the command cd to change the current working directory to the directory which doesn’t exist, we get the system cannot find the path specified error in the cmd window.

Note: The commands given in the below screenshot are applicable for both C: and D: drives or any other drives.

In the below screenshot, the cd command is used in C: drive to change the directory to the existing directory called “javahungry". But when the same command is used to change the non-existing directory called "examples", we get the system cannot find the path specified error in the cmd window. Here, I have shown how to use the cd command using both absolute (using full path)and relative paths(partial path related to current working directory). In both cases, we get the same error. So, to overcome the error, we need to give the correct existing directory path in the cd command.

incorrect directory name

2. When trying to compile the Java file by using the commands cd and javac together in the cmd window



This error occurs when you try to compile the .java file using cd and javac commands together in the cmd window.
The installed Java directory path is C:\Program Files\Java\jdk-14.0.2\bin.
When we try to compile the java file as,
cd C:\Program Files\Java\jdk-14.0.2\bin javac HelloWorld.java
The output will be,
The system cannot find the path specified error is displayed as given below,
using both javac and cd commands in cmd

Java beginners usually try to compile the code like mentioned above.
Instead of trying the above way shown in the screenshot, we can add the path in the environment variable in Windows and try to access it from the folder in which the java file is saved as mentioned below.
We create a java file "HelloWorld" in a directory called examples and add the path of JDK in the Windows environment variable.
There are two ways to add the path in the environment variables in Windows.

Note: Path is an environment variable used by the operating system to locate the executable programs from the cmd window.

Whenever making changes to the path, restart your cmd and try the commands.
1. Add the path temporarily in cmd window as given below,
add the path temporarily
2. Add the path permanently in Windows as mentioned below,
 Go to This PC and right-click ->Go to Properties ->Select Advanced system settings ->Click Environment variables-> Then under User variables, Click New ->give the variable name and value and Click Ok

add the path permanently in windows



add new user variable in windows


After giving the path, you can compile and run the java program from the directory(folder) where the java file exists without setting the path in cmd as mentioned below,
compile and run the java program

3. When the values in Registry Editor-HKEY_CURRENT_USER\Software\Microsoft\CommandProcessor\AutoRun are not cleared



You can try the below steps to get rid of the system cannot find the path specified error in cmd:
1. Open the Registry Editor (press Windows key +R, then type regedit and click OK).
2. Then go to HKEY_CURRENT_USER\Software\Microsoft\Command Processor\AutoRun and clear the values.
3. Also, check HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\AutoRun.

That's all for today, please mention in the comments in case you know any other way of solving the system can not find the path specified error in command prompt.

About The Author

Subham Mittal has worked in Oracle for 3 years.
Enjoyed this post? Never miss out on future posts by subscribing JavaHungry