Move files of todays date

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Danny
Posts: 15
Joined: 30 Oct 2013 22:52

Move files of todays date

#1 Post by Danny » 13 Nov 2013 15:28

Hello,

This codes moves all *.xml files from source folder to target folder, creating on date folder.
I want to move only todays date file to target folder.

File name : PRD_005_14112013_132228_01.XML

Code: Select all

@echo off

set mydate=%date:~-10,2%-%date:~-7,2%-%date:~-4%
Xcopy /E /I "C:\xml_4\xml\*.xml" "D:\Company\%mydate%"

del /s /q "C:\xml_4\xml\*.*"


foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Move files of todays date

#2 Post by foxidrive » 13 Nov 2013 20:47

Did you mean to copy files from subdirectories as well?

Danny
Posts: 15
Joined: 30 Oct 2013 22:52

Re: Move files of todays date

#3 Post by Danny » 13 Nov 2013 21:55

Hello foxidrive,

foxidrive wrote:Did you mean to copy files from subdirectories as well?
YES.

Thanks.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Move files of todays date

#4 Post by foxidrive » 13 Nov 2013 22:05

Code: Select all

@echo off

set mydate=%date:~-10,2%-%date:~-7,2%-%date:~-4%
Xcopy /E /I "C:\xml_4\xml\*.xml" "D:\Company\%mydate%"

del /s /q "C:\xml_4\xml\*.*"


There is a flaw in your code above where you are copying *.xml but then you delete every file, instead of *.xml.

If you replace *.xml and *.* with *%mydate%*.xml then it will operate on XML files with the date in that format in the name.

Danny
Posts: 15
Joined: 30 Oct 2013 22:52

Re: Move files of todays date

#5 Post by Danny » 13 Nov 2013 22:41

Thanks foxidrive.

Post Reply