MathMXC
MathMXC

Reputation: 319

CMD mkdir syntax error

I am kind of new to cmd for I am a linux guy. In the code bellow I am trying to find a .mp3 or .mp4 file and save there path to a file and then move the .mp3/.mp4 into the file. I get a syntax error on the mkdir command

ECHO off
pause
mkdir "/Users/media"
pause
cd /Users/
dir *.mp3 >Users/media/output.txt/s
dir *.mp4 >>Users/media/output.txt/s

pause
for /r %%a IN (*.mp3) do (
move /y "%%a" "/Users/media"
)
pause
for /r %%a IN (*.mp4) do (
move /y "%%a" "/Users/media"
)

thanks any help would be appreciated

Upvotes: 2

Views: 2290

Answers (1)

Marged
Marged

Reputation: 10953

Windows supports forward slashes in many scenarios but prefers backslashes. So you should change the appropriate line to

mkdir \Users\media

If your path contains spaces you have to surround it with quotation marks. In case the users directory does not exist you can add a -p to the command which will have it create the complete hierarchy you specify. Depending on how you use the batch you might want to add a drive letter to your path and check the errorlevel of the mkdir command.

Read more about mkdir here, this site lists the other available commands too.

As you are coming from Linux I want to mention that bash and others can be installed on Windows too, there even are UNIX "emulations" like Cygwin. There are alternatives to batches, for example Windows scripting host which looks more like regular programming and adds support for vbscript and JavaScript. Or you have a look at powershell. Both alternatives create (but I am maybe biased) better, more readable and maintainable code. Batches are often a pain to those that follow you and have to understand and change.

Upvotes: 2

Related Questions