Batch file to delete files older than x hours




















Active 2 years, 3 months ago. Viewed 23k times. I see this - Batch file to delete files older than N days But how can I delete files older than N hours or minutes? Improve this question. Community Bot 1 1 1 silver badge. Please do not read only the most voted answer, read also the other answers.

Several other answers support also smaller time deltas like my answer written yesterday which works with seconds. See this answer for other ideas. Add a comment. Active Oldest Votes. My solution requires an executable, but I found it was the best solution for me.

Find Utils bin Find Utils deps. Improve this answer. Dan Dan 1, 15 15 silver badges 17 17 bronze badges. See this answer for an example. I almost hate to point this out, as you seem to have put a substantial amount of time and effort into your JSC hybrid.

Yep, confirmed. Echo typeof file. DateLastModified echoes date. Tested Date on jsfiddle. Show 4 more comments. Active Oldest Votes. LastWriteTime -lt Get-Date. Improve this answer. Adding the CreationTime in that check can be a good thing too.

I had files with creationTime date set to september I moved them while their LastWriteTime was dated from It's good to understand the difference between Creation Time and Last Write Time, but in this instance, I don't think they are both needed. The question is about clearing out files from a temp folder; I can't imagine I'd ever move old files into a temp folder that I knew was being automatically cleaned. Particularly not if those files had much value. You can definitely get these informations using powershell easily enough.

You would need to use Get-ChildItem with recurse parameter and filter out folders. Edit: Thanks to andyb comment, i removed the timespan in favor for a direct date comparison. Sage Pourpre Sage Pourpre 7, 2 2 gold badges 23 23 silver badges 36 36 bronze badges. No need for a TimeSpan; just use Get-Date.

AddHours -6 — andyb. Silly me, I improved my answer with your suggestion. No problem! To continue this discussion, please ask a new question. Laplink Software, Inc. Neil Laplink. Spiceworks Help Desk. The help desk software for IT. Track users' IT needs, easily, and with only the features you need. Learn More ». Get answers from your peers along with millions of IT pros who visit Spiceworks.

What am I missing? What I want it to do: Copy Files from a local folder to a share. Best Answer. Verify your account to enable IT peers to see that you are a professional. View this "Best Answer" in the replies below ».



0コメント

  • 1000 / 1000