Sign in to follow this  
Followers 0
StOnge

Can AutoIT detect when a file was created?

4 posts in this topic

Hello All,

I am trying to write a script that can be executed every night on a Temporary User Transfer folder on our network. I would like the script to scan the directory and to remove all files that were created over one week ago. I'm not sure if AutoIT can do this.

The only solution I have come up with is just to empty the entire directory and run the script once a week with this:

DirRemove("I:\User Transfer")
DirCreate("I:\User Transfer")

The only problem with this is that it would delete every file in the directory, and I would like it to just remove those that are over one week old.

Any ideas would be greatly appreciated. Thanks so much in advance!


www.stonge.com

Share this post


Link to post
Share on other sites



Try find something in

_Date_Time_GetFileTime

maybe this can help you :)


This world is crazy

Share this post


Link to post
Share on other sites

You can do this with FileGetTime, and the @WDAY macro.


- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

#include <Array.au3>
#include <Date.au3>
#include <File.au3>

;Root folder
$sourceFolder = @ScriptDir & '\'

;Gather files into an array
$fileList = _FileListToArray($sourceFolder, "*", 1)
Dim $found[1]

;Loop through array
For $X = 1 To $fileList[0]
    ;Retrieve creation time of file
    $Date = FileGetTime($sourceFolder & "\" & $fileList[$X], 1, 0)
    ;Format date for use with Date UDF
    $fDate = StringFormat("%s/%s/%s %s:%s:%s", $Date[0], $Date[1], $Date[2], $Date[3], $Date[4], $Date[5])
    ;Calculate age, remove files older than seven days
    If _DateDiff('d', $fDate, _NowCalc()) > 7 Then ; the time
        ;FileDelete($sourceFolder & "\" & $fileList[$X])
        _ArrayAdd($found, $sourceFolder & $fileList[$X])
        ;MsgBox(1, "Files deleted:", $fileList[$X], 1)
    EndIf
    $found[0] = UBound($found)
Next
_ArrayDisplay($found)

Edited by Xenobiologist

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

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