Jump to content
Sign in to follow this  
JoshG

Delete old Files

Recommended Posts

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

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

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

Oh, I only remember the other one that I replied to and didn't see this one until today.


010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

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  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...