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.  

Who is Participating?
SubsunConnect With a Mentor Commented:
If you are trying to copy the log files modified date older than 2 days..

Following PowerShell code will copy all two days old files from C:\logs to C:\Logcopy..
GCI C:\logs | ?{$_.LastWriteTime -lt (Get-Date).adddays(-2)} | Copy-Item -Destination C:\Logcopy

Open in new window

Bill PrewCommented:
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?


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
mkdir c:\delete
robocopy "E:\Logs" c:\Delete /e /MOVE /MINAGE:3 /R:2 /W:30
rmdir c:\delete /s /q
Michael DyerSenior Systems Support AnalystCommented:
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:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.