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.  

Microsoft DOSPowershellVB Script

Avatar of undefined
Last Comment
Michael Dyer

8/22/2022 - Mon
Subash Sundharan

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
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?



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
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Michael Dyer

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: