Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.

In Windows cmd.exe, cd cannot make a UNC path such as \ServerShareFolder the current directory. Use pushd instead:

pushd "\ServerShareFolder"

With command extensions enabled, pushd temporarily maps the network location to an unused drive letter and changes to it. Run popd when you are finished to restore the previous location and remove that temporary mapping. A UNC path is still valid for file operations; this limitation is about the current directory in Command Prompt.

What is a UNC directory?

A UNC (Universal Naming Convention) path identifies a network resource using this form:

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
\servershareoptionalsubdirectory

The server names the computer or host, the share names the shared resource, and any remaining components identify directories within that share. For example, \FileServerPublicReports2026 is a UNC path. By contrast, P: is a drive-letter path that may be mapped to a network share. Microsoft describes UNC paths as fully qualified network paths in its file path format documentation.

UNC paths are not invalid in Windows. Many commands accept them as file or directory arguments. The issue is specifically that the traditional Command Prompt cannot use a UNC path as its current directory in the normal drive-based shell context.

Why cd fails

The documented syntax for cd (also called chdir) is cd [/d] [<drive>:][<path>]. It is designed around drive letters, such as:

cd C:Projects
cd /d D:Builds

The /d option lets cd change both the current directory and the current drive. It does not convert a UNC path into a drive-letter path, so this does not solve the problem:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
cd /d "\ServerShareFolder"

Depending on how Command Prompt was launched, you may see the familiar message UNC paths are not supported as current directories. Defaulting to Windows directory. The exact wording can vary, but the underlying distinction is the same. See Microsoft’s documentation for cd syntax and its archived Q&A on the UNC current-directory message.

Use pushd in Command Prompt

At an interactive Command Prompt, run:

pushd "\ServerShareFolder"

With command extensions enabled, pushd accepts a network path. For a UNC path, it temporarily assigns the share an unused drive letter and changes to the requested directory. Microsoft says it starts with the highest unused letter, normally Z:; the actual letter can differ. Your prompt might then look like Z:Folder>.

To check your current directory, use cd or echo %CD%. When you are ready to return to where you started, run:

popd

popd restores the location saved by pushd and, when command extensions are enabled, removes the temporary drive assignment. Details are in Microsoft’s documentation for pushd and popd.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use a safe pattern in a batch file

Check whether pushd succeeded before running commands that depend on the network directory, then pair it with popd:

@echo off
setlocal

pushd "\FileServerPublicReports" || (
    echo Could not access the network directory.
    exit /b 1
)

rem Commands that use the network directory go here
dir

popd
endlocal

If the batch file should work in its own directory, even when launched from a UNC share, use %~dp0 with pushd:

@echo off
setlocal

pushd "%~dp0" || exit /b 1

rem The batch file's directory is now the current directory.
your-command.exe

popd
endlocal

%~dp0 expands to the drive and path of the running batch file. If that path is UNC, pushd can provide the temporary drive-letter context. Using cd /d "%~dp0" is not a substitute when the batch file is on a UNC share.

If pushd does not work

pushd does not grant access to a share or bypass authentication. First check that the UNC path is spelled correctly, begins with two backslashes, and points to a directory. Then test the share directly:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
dir "\ServerShare"

If that fails, investigate whether the server is reachable, the share name is correct, and the account running the command has permission. DNS or network connectivity, credentials, or a different execution account can also be the cause. A path with spaces should be quoted, for example pushd "\ServerShareFolder With Spaces".

The network-path behavior of Command Prompt’s pushd depends on command extensions. To test in a new shell with extensions enabled, run:

cmd /e:on
pushd "\ServerShareFolder"

If this works but the original shell does not, extensions may be disabled in that environment. The cmd documentation covers the /e:on and /e:off switches and extension settings. Opening a shell with cmd /e:on is a better first diagnostic than changing registry settings.

For batch paths with characters such as &, |, <, >, ^, parentheses, or !, Command Prompt’s parsing rules may require extra care. In particular, delayed expansion can affect exclamation marks; that is separate from UNC path support.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Choose the right approach

  • Use pushd and popd when a Command Prompt script needs to work relative to a UNC directory, especially if the program expects a drive-letter working directory and the temporary letter does not matter.
  • Pass a UNC path directly when the command accepts full paths and you do not need to change the current directory. For example: dir "\ServerShareReports" or copy "\ServerShareSourcefile.txt" "C:Temp".
  • Use net use when a legacy program requires a particular drive letter or you need to control the mapping explicitly. For example:
net use X: "\servershare" /persistent:no
if errorlevel 1 exit /b 1

cd /d X:folder
rem Run the program here

net use X: /delete

Choose a letter that is not already in use, and plan how the mapping will be cleaned up if the script stops early. Mapped drives are scoped to logon sessions: a drive visible in File Explorer may not be available to an elevated process, scheduled task, another user, or service. Microsoft explains this in its guidance on services and redirected drives. Automation should not rely on a mapping created in a different session.

  • Use PowerShell if the workflow is already in PowerShell. It supports UNC locations directly:
Set-Location '\serversharefolder'

To save and restore a location around work, use the PowerShell location stack:

Push-Location '\serversharefolder'
try {
    Get-ChildItem
}
finally {
    Pop-Location
}

PowerShell’s Push-Location (also aliased as pushd) is a PowerShell command, not the cmd.exe built-in. See Microsoft’s PowerShell documentation.

subst is not the default fix for a network UNC path; Microsoft documents it for associating a drive letter with a path such as a local directory. Prefer pushd, a direct UNC argument, PowerShell, or an explicit network mapping as appropriate.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Quick reference

rem Enter a UNC directory in cmd.exe
pushd "\ServerShareFolder"

rem Return to the previous directory
popd

rem Enable command extensions in a new cmd process
cmd /e:on

rem Use a UNC path without changing the current directory
dir "\ServerShareFolder"

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.