Move and rename log files


I wonder if somebody has a powershell/vb/batch script to move files which are older than 4 hours (create time) to different location and rename those with adding create date & time at end.

Example: c:\*.log move it to d:\LogDir\*.log directory and rename those to *-mm-dd-yy-hh-mm.log

Assistance would be appreciated.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Try this... Change the <folder> and <new location> to the correct values and remove -whatif if it works as you suspect.
$files = dir <folder> *.log | ?{$_.LastWriteTime -gt (Get-date).addhours(-4)}
foreach($file in $files)
   $FileName = $ -replace $file.Extension,""
   $NewName = "${FileName}$(Get-date -f "MM-dd-yy-HH-mm").log"
   rename-item -path $file.fullname -newname $NewName -whatif
   Move-Item $NewName -dest <new location> -whatif

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
try this one - it is vbscript.  rename the file file to .vbs.
if you do not want to see the output, put a ' in front of the wscript.echo lines.  if you get responses in a pop-up message, change the default script host on your pc to use cscript.exe instead of wscript.exe using this command:  C:\>cscript //h:cscript

AmitTankAuthor Commented:
thanks for the A.
AmitTankAuthor Commented:
Thanks for sharing the script... :)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.