Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to create a batch script that will open a program in a different environment (so I can make a portable version of it).

I use this set APPDATA=%CD%\data to tell it to do that. The problem I'm facing is that I get the following error when the batch starts:

CMD.EXE was started with the above path as the current directory. UNC paths are not supported. Defaulting to Windows directory.

I want to, instead use the cd command to change it to the batch directory. Is there an easy way to do this?

share|improve this question
up vote 1 down vote accepted

If it is on a network drive you might still have issues unless you map the drive buy why not do the following?

APPDATA=%~dp0
cd /d %APPDATA%

By doing a cls you can also clear the error but it the script is run from a UNC path you will receiving this error, you will just have to map it or CLS the error out.

share|improve this answer

Try putting this in the batch:

pushd "%~p0" 2> nul
pushd "\\%~p0" 2> nul

If started from a UNC folder, the 1st line will fail, but the 2nd will work.

If started from a drive mapped folder, the 2nd line will fail, but the 1st will work.

Either way, the current folder will be where the batch file is sitting, and you can change folders from there.

Later, you can use cd to show which folder you are working from.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .