Sign in to follow this  
Followers 0
MadCoder

Deleting Directory from date

5 posts in this topic

I writing a script that connects to our svn and dumps the contents for nightly builds and I would like to know how I would

scan my target directory for directories older than 3 days and delete them? Now sure exactly what safe steps to take.

Share this post


Link to post
Share on other sites



I don't know whether there's a way to get the Folder's Time, but you could scan the whole Folder for Files which are newer than 3 days (FileGetTime) and if you don't find any, delete the folder.

Very slow though.

Share this post


Link to post
Share on other sites

Hi,

#Include <File.au3>
#Include <Date.au3>

$startfolder = "" ; Put here your start folder without ending backslash
$folderList=_FileListToArray($startfolder, 2) ; list folders into array
If @Error=1 Then Exit
For $i = 1 To UBound ($folderList) - 1
    $foldertime = FileGetTime ($startfolder & "\" & $folderList [$i])
    $diff = _DateDiff ("D", $foldertime [0] & "/" & $foldertime [1] & "/" & $foldertime [2], _NowCalcDate () )
    If $diff > 3 Then DirRemove ($startfolder & "\" & $folderList [$i], 1)
Next

;-))

Stefan

Share this post


Link to post
Share on other sites

All,

I know this is an old topic, but I need exactly what it does. But I cannot get it to work? If I turn it into an .exe or leave it as a script, it just stops without any errors?

Ideas?

RichardT


"so much work, so little brains..."

Share this post


Link to post
Share on other sites

All,

I know this is an old topic, but I need exactly what it does. But I cannot get it to work? If I turn it into an .exe or leave it as a script, it just stops without any errors?

Ideas?

RichardT

Stefan's code looks fine, are you sure you have the directory location correct? Also, are your test files over 3 days old?


[center][/center]

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  
Followers 0