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
Avatar of SubSun
Flag of India image

Blurred text
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
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?


Avatar of footech
Flag of United States of America image

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?
Avatar of Veegertx
Flag of United States of America image

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
Avatar of Michael Dyer
Michael Dyer
Flag of United States of America image

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:

VB Script
VB Script

VBScript (Visual Basic Scripting Edition) is an interpreted scripting language developed by Microsoft that is modeled on Visual Basic, but with some important differences. VBScript is commonly used for automating administrative and other tasks in Windows operating systems (by means of the Windows Script Host) and for server-side scripting in ASP web applications. It is also used for client-side scripting in Internet Explorer, specifically in intranet web applications.

Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews


IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo