You may often need to access a file or a folder that is placed on a different device using the Command Line Interface (CLI) on your Windows 10 device. It may be because you need to execute the package or for any other reason. However, the simple Change Directory (cd) command in the Command Prompt is not sufficient to navigate to a path over the network.
This article discusses various methods and techniques you can use to access or even map network paths onto your device using the command lines.
- 1 Traditional methods to map and access network paths in Windows 10
- 2 How to access network path using command line in Windows 10
- 3 Closing words
- 4 Continue Reading:
Traditional methods to map and access network paths in Windows 10
Normally, users would access a network path using either Run or directly from the File Explorer. We shall also be discussing this method so that you understand the differences when we try and access a network path through the CLI.
- To map a network drive using File Explorer, click on This PC in the left navigation bar, and then click Map a network drive from the top menu within the Explorer.
- A Map network drive wizard will now popup. Select a vacant alphabet to assign to the new drive, enter its path in the field below, select your preference by checking the boxes below, and then click Finish.
Note that the IP address on the network path can be changed to the name of the device. Moreover, the path is not case-sensitive, therefore the capital and small should not matter.
- You will now be prompted to enter the credentials of the destination user account to access the path. Enter the correct credentials and click OK.
You can now check that the path should be added as an attached drive on your PC in the File Explorer.
You can also access the network path directly through the Explorer or Run by typing in the path and providing the correct credentials.
This is a convenient way to map and access network drives using the Graphical User Interface (GUI). However, what if you need to access certain files using the CLI and then execute them directly from there? We have a solution for you down below.
How to access network path using command line in Windows 10
You might know how to move around within your own computer using the Command Prompt or Windows PowerShell. However, moving to a path over the network is a different story.
Access network path from Command Prompt using Pushd command
Changing directories within the Command Prompt can be done by using the cd command. However, this does not work when accessing a remote path, and you will get an error stating “CMD does not support UNC paths as current directories.”
The Universal Naming Convention (UNC) path is any path consisting of double forward or backslashes followed by a computer name/ IP address. This is not supported by Command Prompt and does not understand the command.
You need to use the pushd command to access a network path from the Command Prompt. Use the command below to do so:
Replace NetworkPath with the path to the location you wish to access over the network, such as in the example below:
Tip: If the location folder has space in its name, enclose the entire NetworkPath in inverted-commas (“”).
As you may notice in the image above, entering the command changed the working directory to z. This letter has been automatically assigned to the path, which is now also mapped and can be seen as a drive using the File Explorer.
Another way to access a network path from Command Prompt is to manually map it using the File Explorer traditionally, and then use the cd command to change the directory using the new assigned drive letter, as in the image below:
Map network path from Command Prompt using Net Use command
Another quick way to access a network path from Command Prompt is to use the Net Use command to initially map the location. This method allows you to mount the network drive as well as set a custom letter for it.
Use the command below to map location over the network:
net use Letter: NetworkPath /PERSISTENT:YES
Replace Letter with a vacant drive letter for the path and replace NetworkPath with the path to the location you want to access. Here is an example of using this command:
Now that the location has been mapped, simply use the cd command to access it.
Access network path from PowerShell using cd command
Unlike the Command Prompt, Windows PowerShell understands the UNC path, hence is able to use the cd command to change its directory. This method is easier as it is like accessing a local location rather than something over the internet.
Use the command below in PowerShell to access a network path:
Replace NetworkPath with the location you wish to access, as in the example below:
Mind you, this approach does not map the location, but only lets you access it via Windows PowerShell.
There are multiple ways to access a network path using just the CLI. However, it is up to you to decide which method to use.
If you are required to run certain scripts after accessing the network path, we recommend that you use PowerShell to do so. However, if you have to perform basic tasks such as executing a package and obtain results within the CLI, the Command Prompt Should be enough.
If you simply want to browse the location, the traditional File Explorer should be sufficient for that.