I got for example n folders {C:/tst1,C:/tst2,C:/tst3,C:/tst1} and in those folders I need delete files which were created like >5 hours I know forfile can't delete with hours option what else could I use ?
Asked
Active
Viewed 39 times
-1
-
tried that answer didn't helped – masterjiji Aug 10 '18 at 07:06
-
There are three answers in that question and two of them I have used successfully at my job. Update your question with what you have tried. – Squashman Aug 10 '18 at 07:08
-
Mofi, also posted a link to an answer in one of his comments. His code is normally very solid. – Squashman Aug 10 '18 at 07:18
-
You could also use [Dave Benham's JTimeStamp](https://www.dostips.com/forum/viewtopic.php?f=3&t=7523) to calculate a time difference. Use a `FOR` command to get the time stamp of the file. Then use the date and time variables for the current time and feed it to JTimeStamp to get the time difference. – Squashman Aug 10 '18 at 07:22
1 Answers
0
You could probably utilise PowerShell
from your batch file for this.
Given your provided information you could try the following:
@PowerShell -NoP "GCI 'C:\tst*\*'|?{!$_.PSIsContainer -And ($_.LastWriteTime -LT (Get-Date).AddHours(-5))}|Rm -Wh"&Pause
This will not delete the files, for your protection, it will just show you those it would delete.
If you are satisfied with the output you can replace -Wh"&Pause
at the end of the line with -Fo"
.

Compo
- 36,585
- 5
- 27
- 39