Jump to content
Sign in to follow this  
marcusdoc

Folder deletion based upon date

Recommended Posts

marcusdoc

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=10326

The 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 by marcusdoc

Share this post


Link to post
Share on other sites
MHz

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 by MHz

Share this post


Link to post
Share on other sites
marcusdoc

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.

<{POST_SNAPBACK}>

... can't be that easy ... thanks

(thought I tried the that ... obviously did not do it correctly)

Share this post


Link to post
Share on other sites
marcusdoc

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)

Share this post


Link to post
Share on other sites
Jos

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)

<{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 : 20050601

so all folder as of 1 day old will be deleted : 20050531

20050601-20050531 = 70


SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
marcusdoc

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 by marcusdoc

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×