Page 1 of 1

Move files of todays date

Posted: 13 Nov 2013 15:28
by Danny
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\*.*"


Re: Move files of todays date

Posted: 13 Nov 2013 20:47
by foxidrive
Did you mean to copy files from subdirectories as well?

Re: Move files of todays date

Posted: 13 Nov 2013 21:55
by Danny
Hello foxidrive,

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

Thanks.

Re: Move files of todays date

Posted: 13 Nov 2013 22:05
by foxidrive

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.

Re: Move files of todays date

Posted: 13 Nov 2013 22:41
by Danny
Thanks foxidrive.