marcusdoc Posted May 23, 2005 Share Posted May 23, 2005 (edited) I have network cams that place motion detected images into a folder (name of folder based upon date ie. 5_23_2005); there are ~3500 images taken per day.Help was given regarding this to by performing a recursive directory scan and deleting the files older than 14 days.http://www.autoitscript.com/forum/index.php?showtopic=10326The problem was that 3500*15=52500 files to scan takes a long time.Need some help with a script that would do a recursive directory scan and delete folders based upon date. (I don't see anything within AutoIt regarding folder date creation aquisition). Edited May 23, 2005 by marcusdoc Link to comment Share on other sites More sharing options...
MHz Posted May 23, 2005 Share Posted May 23, 2005 (edited) FileGetTime can get you the creation date of a folder. Here is the example for it. $t = FileGetTime("Folder Address here", 1) If Not @error Then $yyyymd = $t[0] & "/" & $t[1] & "/" & $t[2] MsgBox(0, "Creation date of folder", $yyyymd) EndIf Just do a filesearch of just folders. Edited May 23, 2005 by MHz Link to comment Share on other sites More sharing options...
marcusdoc Posted May 23, 2005 Author Share Posted May 23, 2005 FileGetTime can get you the creation date of a folder.Here is the example for it.$t = FileGetTime("Folder Address here", 1) If Not @error Then $yyyymd = $t[0] & "/" & $t[1] & "/" & $t[2] MsgBox(0, "Creation date of folder", $yyyymd) EndIfJust do a filesearch of just folders.<{POST_SNAPBACK}>... can't be that easy ... thanks(thought I tried the that ... obviously did not do it correctly) Link to comment Share on other sites More sharing options...
marcusdoc Posted May 25, 2005 Author Share Posted May 25, 2005 finished the script - no logging of deletions, just do a single directory scan and find the folders older than 14 days and delete them made from scripts of others on the forum (thanks guys) $edate=@YEAR & @MON & @MDAY $location = "D:\Levo\Cam1\" $search = FileFindFirstFile($location & "*.*") ; Check if the search was successful If $search = -1 Then MsgBox(0, "Error", "No files/directories matched the search pattern") Exit EndIf While 1 $file = FileFindNextFile($search) If @error Then ExitLoop If $file = "." Or $file = ".." Then ContinueLoop $N_TFILE = $location & "\" & $file If StringInStr(FileGetAttrib( $N_TFILE ),"D") > 0 Then $t = FileGetTime($N_TFILE, 1) $yyyymd = $t[0] & $t[1] & $t[2] if $edate-$yyyymd > 14 Then DirRemove ($N_TFILE, 1) endif endif WEnd ; Close the search handle FileClose($search) Link to comment Share on other sites More sharing options...
Developers Jos Posted May 25, 2005 Developers Share Posted May 25, 2005 finished the script - no logging of deletions, just do a single directory scan and find the folders older than 14 days and delete themmade from scripts of others on the forum (thanks guys)$edate=@YEAR & @MON & @MDAY $location = "D:\Levo\Cam1\" $search = FileFindFirstFile($location & "*.*") ; Check if the search was successful If $search = -1 Then MsgBox(0, "Error", "No files/directories matched the search pattern") Exit EndIf While 1 $file = FileFindNextFile($search) If @error Then ExitLoop If $file = "." Or $file = ".." Then ContinueLoop $N_TFILE = $location & "\" & $file If StringInStr(FileGetAttrib( $N_TFILE ),"D") > 0 Then $t = FileGetTime($N_TFILE, 1) $yyyymd = $t[0] & $t[1] & $t[2] if $edate-$yyyymd > 14 Then DirRemove ($N_TFILE, 1) endif endif WEnd ; Close the search handle FileClose($search)<{POST_SNAPBACK}>Don't think that you can just subtract current date - folderdate to get folders older than 14 days.... you have to use something like _DateDiff()eg assume today is june 1 2005 : 20050601so all folder as of 1 day old will be deleted : 2005053120050601-20050531 = 70 SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
marcusdoc Posted May 28, 2005 Author Share Posted May 28, 2005 (edited) Very excellent point - here is the revision #include <Date.au3> $location = "D:\Levo\Cam1\" $search = FileFindFirstFile($location & "*.*") ; Check if the search was successful If $search = -1 Then MsgBox(0, "Error", "No files/directories matched the search pattern") Exit EndIf While 1 $file = FileFindNextFile($search) If @error Then ExitLoop If $file = "." Or $file = ".." Then ContinueLoop $N_TFILE = $location & $file If StringInStr(FileGetAttrib( $N_TFILE ),"D") > 0 Then $t = FileGetTime($N_TFILE, 1) $yyyymd = $t[0] & "/" & $t[1] & "/" & $t[2] if _DateDiff( 'D', $yyyymd, _NowCalcDate()) > 14 Then DirRemove ($N_TFILE, 1) endif endif WEnd ; Close the search handle FileClose($search) Edited May 30, 2005 by marcusdoc Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now