1

I am trying to get a batch file to create a folder on the desktop with a text file inside of it. Every-time i try to run this line of code it gives my the error that "The filename, directory name, or volume label syntax is incorrect."

echo ========================
::CREATE FILES START
cd /d C:
md Title
echo.>"C:\Users\%USERACCOUNT%\Desktop\Example\example.txt"
::CREATE FILES END
echo Done!
pause >nul

3 Answers 3

1

Your code is changing to drive C, then creating GeoHunt2015 in root. Then you try to echo the file into non-existent folder on desktop, hence the error.

This assumes your %userprofile% is "c:\users\name"

md "%USERPROFILE%\Desktop\GeoHunt2015"
echo.>"%USERPROFILE%\Desktop\GeoHunt2015\Mission_Instuctions.txt"

or you can cd to desktop

echo ========================
:: CREATE FILES START
    cd /d "%USERPROFILE%\Desktop\"
    md GeoHunt2015
    echo. >"GeoHunt2015\Mission_Instructions.txt"
:: CREATE FILES END
    echo Done!
    pause >nul
Sign up to request clarification or add additional context in comments.

Comments

1

Is %USERACCOUNT% defined? Is the echo actually causing the issue? Try commenting out stuff until you are sure that the echo is causing the syntax error.

A couple things I can see. You're switching to the C: directory, then making the GeoHunt2015 folder, but then attempting to echo into the GeoHunt2015 folder on your desktop.

Try this echo instead:

echo.>"C:\GeoHunt2015\Mission_Instructions.txt"

Comments

0

Try using

mkdir "C:\%USERPROFILE%\Desktop\GeoHunt2015"
echo.>"C:\%USERPROFILE%\Desktop\GeoHunt2015\Mission_Instuctions.txt"

as you had in your original version of the question.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.