Jump to content
Sign in to follow this  
MadCoder

Deleting Directory from date

Recommended Posts

MadCoder

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
L3viathan2142

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
99ojo

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
RichardT

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
Affe

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.