| 1. |
Solve : Batch file for deleting files outside of time window? |
|
Answer» Hi folks, Q. I have some old pictures, mostly JPGs, that I have copied to my wife’s PC, and the dates for the files are different on her PC than on mine. Why is that and which ones are correct? My PC is running Windows XP, and hers has Windows 7.The above article goes on to explain the special case of JPEG files. Thanks for the reply Geek, sounds like "date taken" may be an option. Data can be viewed in windows explorer by "date taken". I'm less convinced now that my problem is in fact the "date created" issue because I copied a bunch of photos (at 1pm), ran the macro, and it deleted the photos DESPITE appearing to pass the "keep" criteria of being created between 8am and 5pm. In order to get the macro working I had to change the file path and add an action to the FOR loop. In its original version the macro simply has Code: [Select]set "action=" and will hang up until something is added after the equals sign. I'm not sure if that's part of my problem as well. So the macro I'm currently trying to run is as follows: Code: [Select]echo off :: (modified) original code by Salmon Trout - Oct 2014 :: - deletes files with creation time earlier than 08:00 and after 16:59 (on files from any day) :: > "%temp%\fhour.vbs" echo Set fso = CreateObject("Scripting.FileSystemObject") >> "%temp%\fhour.vbs" echo Set f = fso.GetFile(trim(wscript.arguments(0))) >> "%temp%\fhour.vbs" echo wscript.echo Hour (f.DateCreated) for %%A in ("c:\349GOPRO\*.*") do ( for /f "delims=" %%B in ('cscript /nologo "%temp%\fhour.vbs" "%%~fA"') do ( set "action=Keep" if %%B lss 8 set action=Delete if %%B geq 18 set action=Delete if /i not "%%~fA"=="%~f0" if defined action echo deleting "%%~fA" & del "%%~fA" ) ) pause FYI photos are being taken with Gopro Hero 3 and 4's and I'm running a couple PCs, one with windows 7 and one with windows 10. Currently it is deleting everything regardless of date created/modified/taken. If anyone knows what my problem is I'd greatly appreciate some help. Thanks! The set "action=" was there for a reason, as you've discovered With each file, it unsets the variable via set "action=", then it sets that variable if the hour of the DateCreated is less than 8 or greater than 18. Since you've changed it to always set the variable, it now deletes every file. I'd expect that what is seen as a hang may be that it is processing many files which do not meet the criteria. It will only output information when it deletes files. Also, regarding your original notes regarding modification dates, You can change the DateCreated line reference to this to change the date being used: Code: [Select]>> "%temp%\fhour.vbs" echo wscript.echo Hour (f.DateLastModified)Holy crap you're right and it works! I have been SAVED many hours of manual deleting. Thanks a ton for the response. JeremyI suppose if you would have read the code and took the time to understand it you could have seen how obvious it was to fix. https://ss64.com/vb/filesystemobject.html |
|