0

I am creating a batch script for which I have a script that is giving me a frustrating error. The location the batch file is being excecuted from is C:\Users####\Desktop\Sp2\Sp2.bat. I want the file to prompt the user if it wants to make a batch file. I got that down. I used the code

echo Would you like to create a directory to output the files to? set /p mkdir=[Y/N] if %mkdir%==Y ( goto :mkdir ) ELSE ( goto :numset ) 

This part works fine. Now here's where the problem arises:

:mkdir echo Enter a name for your folder. set /p foldername= MD %~d0\%foldername% goto :numset 

I this keeps giving me the error "The syntax of this command is incorrect."Can anyone give me a solution to this problem?

2 Answers 2

1

%~d0 gives you the drive only. To get drive and path, use %~dp0:

MD %~dp0%foldername% 

The complete listing of %~?0 is well hidden. See: for /?

Sign up to request clarification or add additional context in comments.

Comments

0

%~d0 expands to a drive of the batchfile. Users don't have permission to create folders in the root of a drive. So it will never work.

Plus the path seperator is \ not the switch character /.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.