Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I want to Copy/Move files in Windows XP from Desktop(a Folder) to My Document(another Folder), which was created by same Batch File on Current Date in Format DD/MM/YYYY.

This is working fine when .BAT File is in Desktop Folder.

@echo off
set date="%date:~7,2%-%date:~4,2%-%date:~10,4%"
mkdir %date%
copy *.txt \%date%
pause

Now what this .BAT is doing is, creating Folder 18-01-2013 on Desktop and coping all .TXT files in this Folder.

But this is not working,

@echo off
set date="%date:~7,2%-%date:~4,2%-%date:~10,4%"
mkdir %USERPROFILE%\My Documents\%date%
copy %USERPROFILE%\desktop\*.txt %USERPROFILE%\My Documents\%date%
pause

This .BAT File is creating these folders;

  1. In C Drive>Documents
  2. On Desktop (and, Chandel>My, Documents>18-01-2013, Settings>Anshuman)

Any help in this regard is highly appreciated!

Thanks in advance!

Anshuman Chandel

share|improve this question
1  
I highly recommend giving this tutorial a read through. I believe the answer you seek is in there. I'm sorry, but I do not have time to research the answer for you. Batch File Tutorial –  Josh Campbell Jan 18 '13 at 4:20

1 Answer 1

up vote 0 down vote accepted

You need to place double-quotes (") around your paths that contain, or may contain, spaces or other special characters. To be safe, I always quote all paths in scripts, just in case. Also, you want to remove the quotes from around the variable values that will later be components in other paths. So, remove the quotes from the set date line and add them to the next two lines.

So your script should be:

@echo off
set date=%date:~7,2%-%date:~4,2%-%date:~10,4%
mkdir "%USERPROFILE%\My Documents\%date%"
copy "%USERPROFILE%\desktop\*.txt" "%USERPROFILE%\My Documents\%date%"
pause
share|improve this answer
    
Hurry! It's Working Now, Many Thanks! @charleswj81 –  Anshuman Chandel Jan 18 '13 at 5:23

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.