Sign in to follow this  
Followers 0
JoshG

Delete old Files

9 posts in this topic

looking for help in deleting files by date or by date age(120 days) within a specific folder using a specific file type *.att

Thanks!!!

Share this post


Link to post
Share on other sites



JoshG,

First of all, let me be the first to say RTFM!

Look up FileExists() and FileGetTime().

4Eyes

Share this post


Link to post
Share on other sites

looking for help in deleting files by date or by date age(120 days) within a specific folder using a specific file type *.att

Keep this as part of your list to read up on:

FileOpenDialog

FileFindFirstFile

FileFindNextFile

FileGetAttrib

FileDelete


Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

One way (of many):

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

Local $Folder, $FileList, $FileType = '*.att', $ScavangeDate = 120

$Folder = FileSelectFolder('Choose The Diretory To Scavange For Old Files', '')
If @error Then Exit

$FileList = _FileListToArray($Folder, $FileType, 1)
If @error Then Exit MsgBox(270352, 'Fatal Error', 'No "att" files in:' & @LF & $Folder)

For $i = $FileList[0] To 1 Step -1
    Local $FileDate = FileGetTime($Folder & '\' & $FileList[$i])
    If IsArray($FileDate) Then
        Local $Date = $FileDate[0] & '/' & $FileDate[1] & '/' & $FileDate[2] & ' ' & $FileDate[3] & ':' & $FileDate[4] & ':' & $FileDate[5]
        If _DateDiff('D', $Date, _NowCalc()) >= $ScavangeDate Then ContinueLoop
    EndIf
    _ArrayDelete($FileList, $i)
Next
If UBound($FileList) - 1 = 0 Then Exit MsgBox(270352, 'Completed', 'No old "att" files in:' & @LF & $Folder)
$FileList[0] = UBound($FileList) - 1
_ArrayDisplay($FileList, 'Old Files To Be Deleted')

Local $Confirm = MsgBox(270628, 'Confirmation', 'Continue with File Deleteion(s)?')
Select
    Case $Confirm = 6 ;Yes
        For $i = 1 To $FileList[0]
            FileRecycle($Folder & '\' & $FileList[$i])
        Next
    Case $Confirm = 7 ;No
EndSelect

Edited by Varian

Share this post


Link to post
Share on other sites

One way (of many):

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

Local $Folder, $FileList, $FileType = '*.att', $ScavangeDate = 120

$Folder = FileSelectFolder('Choose The Diretory To Scavange For Old Files', '')
If @error Then Exit

$FileList = _FileListToArray($Folder, $FileType, 1)
If @error Then Exit MsgBox(270352, 'Fatal Error', 'No "att" files in:' & @LF & $Folder)

For $i = $FileList[0] To 1 Step -1
    Local $FileDate = FileGetTime($Folder & '\' & $FileList[$i])
    If IsArray($FileDate) Then
        Local $Date = $FileDate[0] & '/' & $FileDate[1] & '/' & $FileDate[2] & ' ' & $FileDate[3] & ':' & $FileDate[4] & ':' & $FileDate[5]
        If _DateDiff('D', $Date, _NowCalc()) >= $ScavangeDate Then ContinueLoop
    EndIf
    _ArrayDelete($FileList, $i)
Next
If UBound($FileList) - 1 = 0 Then Exit MsgBox(270352, 'Completed', 'No old "att" files in:' & @LF & $Folder)
$FileList[0] = UBound($FileList) - 1
_ArrayDisplay($FileList, 'Old Files To Be Deleted')

Local $Confirm = MsgBox(270628, 'Confirmation', 'Continue with File Deleteion(s)?')
Select
    Case $Confirm = 6 ;Yes
        For $i = 1 To $FileList[0]
            FileRecycle($Folder & '\' & $FileList[$i])
        Next
    Case $Confirm = 7 ;No
EndSelect

Thanks so much for the help!!!!!

Share this post


Link to post
Share on other sites

Why make a 2nd thread when you already got answered in the first?

Look at the time. There were no answer then. And the other is (was) in the examples forums. Josh kinda messed up.

Share this post


Link to post
Share on other sites

Hi Friends,

Subject:- Required below AUTOIT script need to modify

*.att file should be deleted with asking user (operator)

must done automatically

condition:- run on back ground does'nt affect other application

thank you

============================================================================

#include <Array.au3>

#include <Date.au3>

#include <File.au3>

Local $Folder, $FileList, $FileType = '*.att', $ScavangeDate = 120

$Folder = FileSelectFolder('Choose The Diretory To Scavange For Old Files', '')

If @error Then Exit

$FileList = _FileListToArray($Folder, $FileType, 1)

If @error Then Exit MsgBox(270352, 'Fatal Error', 'No "att" files in:' & @LF & $Folder)

For $i = $FileList[0] To 1 Step -1

Local $FileDate = FileGetTime($Folder & '\' & $FileList[$i])

If IsArray($FileDate) Then

Local $Date = $FileDate[0] & '/' & $FileDate[1] & '/' & $FileDate[2] & ' ' & $FileDate[3] & ':' & $FileDate[4] & ':' & $FileDate[5]

If _DateDiff('D', $Date, _NowCalc()) >= $ScavangeDate Then ContinueLoop

EndIf

_ArrayDelete($FileList, $i)

Next

If UBound($FileList) - 1 = 0 Then Exit MsgBox(270352, 'Completed', 'No old "att" files in:' & @LF & $Folder)

$FileList[0] = UBound($FileList) - 1

_ArrayDisplay($FileList, 'Old Files To Be Deleted')

Local $Confirm = MsgBox(270628, 'Confirmation', 'Continue with File Deleteion(s)?')

Select

Case $Confirm = 6 ;Yes

For $i = 1 To $FileList[0]

FileRecycle($Folder & '\' & $FileList[$i])

Next

Case $Confirm = 7 ;No

EndSelect

===============================================================================

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