jjjjjdude
jjjjjdude

Reputation: 109

How to create a text file inside a folder on the desktop using batch

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

Upvotes: 1

Views: 3803

Answers (3)

sjoy
sjoy

Reputation: 492

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

Upvotes: 1

Randy Cork
Randy Cork

Reputation: 45

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"

Upvotes: 1

Magoo
Magoo

Reputation: 80211

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.

Upvotes: 0

Related Questions