• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 131
  • Last Modified:

Delete files and folders in path older than one hour by batch

Hi all,

I can't seem to find a simple way of removing all the files (and folders) in say... c:\temp that are older than 1 hour.

Is there a simple solution to this?

Cheers.
0
tegenius
Asked:
tegenius
2 Solutions
 
Chris HInfrastructure ManagerCommented:
What OS and exact version?
0
 
oBdACommented:
Simplest version is probably Powershell. The following command is in test mode will not delete anything yet, it will just list what it would delete. Remove the "-WhatIf" argument at the end to run it for real.
Get-ChildItem "C:\Temp" -File -Recurse | ? {$_.LastWriteTime -lt (Get-Date).AddHours(-1)} | Remove-Item -WhatIf

Open in new window

0
 
Bill PrewCommented:
Have you looked at this great, free utility?

http://www.horstmuc.de/win/delage.htm
http://www.horstmuc.de/wbat32.htm

~bp
0
 
tegeniusAuthor Commented:
Two great solutions. Thank you so much :) - One command prompt based (which is just what I needed) and powershell. Perfect!
0
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.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now