Link to home
Start Free TrialLog in
Avatar of nav2567
nav2567Flag for United States of America

asked on

copy files with time-stamp specific.

I need to copy some log files from a log folder daily.  The time-stamp of the log files is from two days ago to the time of the copy.  

Please advise how to do it.  

DOS script is just fine.  

Thanks.
ASKER CERTIFIED SOLUTION
Avatar of SubSun
SubSun
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Bill Prew
Bill Prew

Can you be a little more specific.

Do you want to copy all the files in the folder each day?

Where are the files going to?

Do you only want to copy a certain date or age of files?

How does the time stamp factor in, and is that inside the data of the file, or in the file name?

Etc...

~bp
I think you mean anything newer than 2 days ago, in which case you would just need to change the "-lt" in Subsun's script to "-gt".  If you want to include any files created on that day (for example if the script is run on 9/12 at 11 a.m. and you want to include anything created on 9/10 or newer and not just newer than 9/10 11 a.m.), then we could modify it to be
GCI C:\logs | ?{$_.LastWriteTime -gt (Get-Date).adddays(-2).Date} | Copy-Item -Destination C:\Logcopy

Open in new window

Last question would be are you interested in the LastWriteTime or the CreationTime?
You said Dos ok. Use the Retry and wait in case they are open

@echo off
Robocopy "D:\Logs" "E:\Logs" /v /mir /R:2 /W:30
pause
mkdir c:\delete
robocopy "E:\Logs" c:\Delete /e /MOVE /MINAGE:3 /R:2 /W:30
pause
rmdir c:\delete /s /q
Veegertx's solution looks good.  Robocopy, or "Robust File Copy", is a command-line directory replication command.  It has been available as part of the Windows Resource Kit starting with Windows NT 4.0, and was first introduced as a standard feature in Windows Vista and Windows Server 2008.

If you need a copy for Server 2003, you can get it here:

http://www.microsoft.com/downloads/details.aspx?FamilyID=9D467A69-57FF-4AE7-96EE-B18C4790CFFD&displaylang=en