Jump to content

Can AutoIT detect when a file was created?


StOnge
 Share

Recommended Posts

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

Link to comment
Share on other sites

#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

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...