Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am trying to create a batch script that copies the contents of one folder into another. Ihave tried this:

mkdir "c:\Jamie"
cd c:\jamie_DateTimeStamp*
xcopy * "c:\Jamie"
for /D %%f in (c\jamie_*) do rmdir %%f /s /Q

I can get the delete to work but I cannot get the xcopy to work. things to know The Jamie_datetimestap folder can be any date and time so I don't have a constant and I need to use a wildcard. The goal of the script to copy the contents of a folder that has a datetime stamp into a folder that does not have one, then delete the folder with the datetime stamp I cannot simply rename the folder.

share|improve this question
Dave, thanks for fixing my post. – user2487211 Jun 14 at 18:44
can you get it to work without using the '*' and giving it specific targets? – tomArnold Jun 14 at 18:46
You should try this: set curr_date=%DATE:~10,4%-%DATE:~4,2%-%DATE:~7,2% mkdir "c:\Jamie" cd "c:\jamie" mkdir "%curr_date%_backup" – tomArnold Jun 14 at 18:52

1 Answer

If you want to copy subfolders with xcopy you need option /s for subdirectories. You can not use wildcard in cd command though, but you can do a dir /b Jamie* and use this inside the for loop as you do for delete to use as target for cd.

share|improve this answer

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.