Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Batch file to copy files from relative date from today?

Status
Not open for further replies.

JGKWORK

IS-IT--Management
Apr 1, 2003
342
GB
Hi,

Not sure if this is the correct forum for this but I've been tying for hours to figure out a way to write a batch file which simply copies files created say "yesterday" or from the last two days (my choosing) - from one folder to another?

Really appreciate any help.

Many thanks.


 
What have you tried that hasn't worked? Something as simple as this (untested) would do what you describe
Code:
@echo off
set source=c:\somesourcefolder
set dest=d:\somedestinationfolder
SET /P startdate=Enter date in m-d-y format:

xcopy "%source%\*.*" "%destination%" /D:%startdate%

echo copy complete
pause
 
Thanks but what I need is something that does this for a date relative to todays date e.g.

Copy all files from yesterday (so I would change the variable to -1 or two days ago -2) etc, any ideas?

Many thanks.

What I have tried so far is below. Now this works but not when I introduce a file path which has spaces in it (which it has)!:

FORFILES /p C:\temp /s /m *.trn /d -1 /c "CMD /C move /Y @FILE C:\temp\test"
 
I should also have said that there should be no manual uintervention i.e. no inputting of dates as this will be a scheduled batch file. Ta.
 
If I were doing this, I would write a COBOL program to do it. I have writen a similar COBOL program in the past to replace a VB program. The Vb program took hours to copy a few thousand files, the COBOL program took less than 0.1 second.
 
I don't know if this will work, but how about inserting the hex for the " character (0xDE)?
Code:
FORFILES /p [!]"[/!]C:\temp[!]"[/!] /s /m *.trn /d -1 /c "CMD /C move /Y @FILE [!]0xDE[/!]C:\temp\test[!]0xDE[/!]"
 
Bit late with this but thanks all.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top