Jump to content

Delete specific files that are older than a week.


Recommended Posts

@ All, hello, I have been looking in Help and in the forums for the last couple days trying to find the simplest way to script a Filedelete() that will look in a folder and delete specified files that are 1 week older then todays date. I would run this daily so I plan on creating it as a service.

I have looked at FileFindFirstFile() FileFindNextFile() and FileGetTime() and other functions. Here is some of what I have started out with.

#Include <Date.au3>
Global $path = "C:\logfiles\specs08_*_speclog.log "

;To get the current date/time:
$tFile = _Date_Time_EncodeFileTime(@MON, @MDAY, @YEAR, @HOUR, @MIN, @SEC)
    $aFile = _Date_Time_FileTimeToArray($tFile)
    $Current = StringFormat("%02d/%02d/%04d %02d:%02d:%02d", $aFile[0], $aFile[1], $aFile[2], $aFile[3], $aFile[4], $aFile[5])
    MsgBox(4096,"Current date/time:",$Current, 3)

;To locate the files I want to delete:

$locate = FileFindFirstFile($path)  
If $locate = -1 Then
    MsgBox(0, "Error", "No files found")
    Exit
EndIf

While 1
    $files = FileFindNextFile($locate) 
    If @error Then ExitLoop
    MsgBox(0, "File:", $files, 1)
WEnd
FileClose($locate)

;To determine the time of the files I want to delete:

$ftime =  FileGetTime($path, 1)
If Not @error Then
    $yyyymd = $ftime[0] & "/" & $ftime[1] & "/" & $ftime[2]
    MsgBox(0, "Creation date of: ", $yyyymd)
EndIf

It seems this last function only tells the time of the folder that the files are located in and not the files themselves.

I have also tried to do a FileDelete() but it doesn't seem to work, if I had to I could move the files to a temp folder then just delete the folder.

What I am trying to accomplish:

I am trying to locate specific files that are in the same folder and delete ones that are older than 1 week. They will have the same .ext but will have slight name differences. These files are auto created many times everyday and normally I have had to go and manually delete them out of the folder. There can be hundreds of them along with many other files that I have to sort through.

The files are something like this: c:\logfiles\specs08_*_speclog.log where the * can be a range of 6 numbers 0-9.

If anyone has the time to help I would really appreciate it.

Thank You!

Edited by schilbiz
Link to comment
Share on other sites

@ All, hello, I have been looking in Help and in the forums for the last couple days trying to find the simplest way to script a Filedelete() that will look in a folder and delete specified files that are 1 week older then todays date. I would run this daily so I plan on creating it as a service.

I have looked at FileFindFirstFile() FileFindNextFile() and FileGetTime() and other functions. Here is some of what I have started out with.

#Include <Date.au3>
Global $path = "C:\logfiles\specs08_*_speclog.log "

;To get the current date/time:
$tFile = _Date_Time_EncodeFileTime(@MON, @MDAY, @YEAR, @HOUR, @MIN, @SEC)
    $aFile = _Date_Time_FileTimeToArray($tFile)
    $Current = StringFormat("%02d/%02d/%04d %02d:%02d:%02d", $aFile[0], $aFile[1], $aFile[2], $aFile[3], $aFile[4], $aFile[5])
    MsgBox(4096,"Current date/time:",$Current, 3)

;To locate the files I want to delete:

$locate = FileFindFirstFile($path)  
If $locate = -1 Then
    MsgBox(0, "Error", "No files found")
    Exit
EndIf

While 1
    $files = FileFindNextFile($locate) 
    If @error Then ExitLoop
    MsgBox(0, "File:", $files, 1)
WEnd
FileClose($locate)

;To determine the time of the files I want to delete:

$ftime =  FileGetTime($path, 1)
If Not @error Then
    $yyyymd = $ftime[0] & "/" & $ftime[1] & "/" & $ftime[2]
    MsgBox(0, "Creation date of: ", $yyyymd)
EndIf

It seems this last function only tells the time of the folder that the files are located in and not the files themselves.

I have also tried to do a FileDelete() but it doesn't seem to work, if I had to I could move the files to a temp folder then just delete the folder.

What I am trying to accomplish:

I am trying to locate specific files that are in the same folder and delete ones that are older than 1 week. They will have the same .ext but will have slight name differences. These files are auto created many times everyday and normally I have had to go and manually delete them out of the folder. There can be hundreds of them along with many other files that I have to sort through.

The files are something like this: c:\logfiles\specs08_*_speclog.log where the * can be a range of 6 numbers 0-9.

If anyone has the time to help I would really appreciate it.

Thank You!

You're trying to get the time for a filename which has a wildcard character in it. Also, the filename returned by FileFindNextFile is only the filename and doesn't include the full path

Try

#include <Date.au3>
Global $path = "C:\logfiles\";specs08_*_speclog.log

;To get the current date/time:
$tFile = _Date_Time_EncodeFileTime(@MON, @MDAY, @YEAR, @HOUR, @MIN, @SEC)
$aFile = _Date_Time_FileTimeToArray($tFile)
$Current = StringFormat("%02d/%02d/%04d %02d:%02d:%02d", $aFile[0], $aFile[1], $aFile[2], $aFile[3], $aFile[4], $aFile[5])
MsgBox(4096, "Current date/time:", $Current, 3)

;To locate the files I want to delete:

$locate = FileFindFirstFile($path & "specs08_*_speclog.log")
If $locate = -1 Then
    MsgBox(0, "Error", "No files found")
    Exit
EndIf

While 1
    $files = FileFindNextFile($locate)
    If @error Then ExitLoop
    MsgBox(0, "File:", $files, 1)


;To determine the time of the files I want to delete:

    $ftime = FileGetTime($path & $files, 1)
    If Not @error Then
        $yyyymd = $ftime[0] & "/" & $ftime[1] & "/" & $ftime[2]
        MsgBox(0, "Creation date of: ", $yyyymd)
    EndIf

WEnd
FileClose($locate)
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Thanks, that worked as far as showing the date and time on the found files, what about checking the dates to verify against the current date?

Look up

_DateDiff

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Look up

_DateDiff

Something along these lines? I appreciate your time.

$iDateCalc = _DateDiff( 'd', $path & "specs08_*_speclog.log", _NowCalc())
MsgBox( 4096, "", "" & $iDateCalc )oÝ÷ Ù*-éí+%¡Æ­zËayÖ­y©Ýr©j·¬ØhÃ
.Ò,zØ­º(¶­Øî²×^ë^²Øh±ëajÖ«{·ZÊÊ%u8^6jW"²xx²}ýµ¬­êÒ¢}ý¶wvØ^mè"x§«¶íë®*+a¶­zeiÇ¢»ay×¥zب«µÊ.Ò+º{(ëax%G­+ºÙh¢Z­½ªâi¹^Â)e"ëz+uêí¡×¥z×­çâë-«Z­îÝk+(×(«yÛh¶£Æ®¶­sdbb33c¶FFT6Æ2ÒgV÷C³rgV÷C²FVâ·6WfVâF3ð fÆTFVÆWFRb33c¶FFT6Æ2²æòÖGFW"vBWBâW&RfÆTFVÆWFRFöW2æ÷Bv÷&²âà¤VæD`
Link to comment
Share on other sites

If $iDateCalc = "7"

as your if statement, this variable stand for the day after the file was created, not path to the file, so you can't use FileDelete() on it

point out the path of file

[quote]Don't expect for a perfect life ... Expect a least troubles ones[/quote]Contact me : ass@kiss.toWhat I Have Done :Favorites Manager Mangage your favorite's folder, that's coolPC Waker For those who want to save stickersWebScipts Supporter For those who've just started with Web and WebScriptsTemporary Looker Simple but powerful to manage your Temporary folder, you know what you downloaded[UDF] _NumberFormat() Better performance on number display[UDF] _DirGet() What a folder contain [how many (hidden,normal,...) files], with one line of code[UDF] _IsPressEs() Just like _IsPress() but for a group of keys

Link to comment
Share on other sites

All you really need is to change

$ftime = FileGetTime($path & $files, 1)
    If Not @error Then
        $yyyymd = $ftime[0] & "/" & $ftime[1] & "/" & $ftime[2]
        MsgBox(0, "Creation date of: ", $yyyymd)
    EndIf

To

$ftime = FileGetTime($path & $files, 1)
    If Not @error Then
        $cDate = $ftime[0]& $ftime[1] & $ftime[2]
        If (@Year & @Mon & @Mday) - $cDate >= 7 Then MsgBox(0, "TEST", "The file is at least 7 days old")
    EndIf

Edit: Forgot the code tags

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Okay, so if I was going to locate the files this way and verify they are 7 days or older, how would I delete them?

As somewhat mentioned above there will be files in the folder with a similar name convention that I do not want to delete, just the numbers will be different.. here is an example.

specs08_277788_speclog.log 9 days old

specs08_174545_speclog.log 8 days old

specs08_234588_speclog.log 7 days old

specs08_338008_speclog.log 6 days old

specs08_276788_speclog.log 5 days old

specs08_234788_speclog.log 4 days old

specs08_555788_speclog.log 3 days old

specs08_343438_speclog.log 2 days old

#include <Date.au3>
Global $path = "C:\logfiles\"

;To get the current date/time:
$tFile = _Date_Time_EncodeFileTime(@MON, @MDAY, @YEAR, @HOUR, @MIN, @SEC)
$aFile = _Date_Time_FileTimeToArray($tFile)
$Current = StringFormat("%02d/%02d/%04d %02d:%02d:%02d", $aFile[0], $aFile[1], $aFile[2], $aFile[3], $aFile[4], $aFile[5])
MsgBox(4096, "Current date/time:", $Current, 3)

;To locate the files I want to delete:
$locate = FileFindFirstFile($path & "specs08_*_speclog.log")
If $locate = -1 Then
    MsgBox(0, "Error", "No files found")
    Exit
EndIf

While 1
    $files = FileFindNextFile($locate)
    If @error Then ExitLoop
    MsgBox(0, "File:", $files, 1)

;To determine the time of the files I want to delete:
$ftime = FileGetTime($path & $files, 1)
    If Not @error Then
        $Current = $ftime[0]& $ftime[1] & $ftime[2]
        If (@Year & @Mon & @Mday) - $Current >= 7  Then MsgBox(0, "TEST", "The file is at least 7 days old")
    EndIf
WEnd
FileClose($locate)

And again thanks to all who are contributing.

Link to comment
Share on other sites

#include <Date.au3>
Global $path = "C:\logfiles\"

;To get the current date/time:
$tFile = _Date_Time_EncodeFileTime(@MON, @MDAY, @YEAR, @HOUR, @MIN, @SEC)
$aFile = _Date_Time_FileTimeToArray($tFile)
$Current = StringFormat("%02d/%02d/%04d %02d:%02d:%02d", $aFile[0], $aFile[1], $aFile[2], $aFile[3], $aFile[4], $aFile[5])
MsgBox(4096, "Current date/time:", $Current, 3)

;To locate the files I want to delete:
$locate = FileFindFirstFile($path & "specs08_*_speclog.log")
If $locate = -1 Then
    MsgBox(0, "Error", "No files found")
    Exit
EndIf

While 1
    $files = FileFindNextFile($locate)
    If @error Then ExitLoop
    MsgBox(0, "File:", $files, 1)

;To determine the time of the files I want to delete:
$ftime = FileGetTime($path & $files, 1)
    If Not @error Then
        $Current = $ftime[0]& $ftime[1] & $ftime[2]
        If (@Year & @Mon & @Mday) - $Current >= 7  Then MsgBox(0, "TEST", "The file is at least 7 days old")
    FileDelete($path & $file)
    EndIf
WEnd
FileClose($locate)

[quote]Don't expect for a perfect life ... Expect a least troubles ones[/quote]Contact me : ass@kiss.toWhat I Have Done :Favorites Manager Mangage your favorite's folder, that's coolPC Waker For those who want to save stickersWebScipts Supporter For those who've just started with Web and WebScriptsTemporary Looker Simple but powerful to manage your Temporary folder, you know what you downloaded[UDF] _NumberFormat() Better performance on number display[UDF] _DirGet() What a folder contain [how many (hidden,normal,...) files], with one line of code[UDF] _IsPressEs() Just like _IsPress() but for a group of keys

Link to comment
Share on other sites

d4rk has it almost right but I would also make a couple of other simple changes. In particular the way FileDelete() was used will not work because all of the files would be deleted. I just used the MsgBox as a demo (hence the use of Msgbox(0, "TEST", ...

That makes it much sfaer to be sure you have the right files. Another tip, when experimenting with code that deletes files always run it a few times using FileRecycle() instead of FileDelete(). If anything goes wrong you can recover the files.

While 1
    $files = $path & FileFindNextFile($locate)
    If @error Then ExitLoop
    MsgBox(0, "File:", $files, 1)

;To determine the time of the files I want to delete:
$ftime = FileGetTime($files, 1)
    If Not @error Then
        $Current = $ftime[0]& $ftime[1] & $ftime[2]
       ;;If (@Year & @Mon & @Mday) - $Current >= 7  Then MsgBox(0, "TEST", "The file is at least 7 days old")
    If (@Year & @Mon & @Mday) - $Current >= 7  Then FileDelete($path & $file)
    If @Error Then ContinueLoop
    EndIf
WEnd

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Just hang on with this for a few minutes. I know how to make my method fail and after I've had a coffee or two I'll fix it with a rewrite that will solve all your problems.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Okay, here is your solution all wrapped up and ready to go. NOTE: You can #include <file.au3> and remove the _FileListToArray() function but it seems like there is no need to include all the extra code

#Include <date.au3>
$CurrDate = @Year & "/" & @Mon & "/" & @Mday
$Path = "C:\logfiles\"
$fList = _FileListToArray($Path, "*", 1)

For $I = 1 To Ubound($fList)-1
   $File = $Path & $fList[$i]
   $fDate = _DateDiff("D", _File_GetDate($File), $CurrDate)
   If $fDate >= 7 Then MsgBox(0, "TEST", $File & " is " & $fDate & " day(s) old")
  ;;^^^^^^^  Change the MsgBox() to FileDelete($File) and uncoment the next line
  ;;If @Error Then ContinueLoop
Next

Func _File_GetDate($File)
   $File = FileGetShortName($File)
   $Ft = ""
   $fTime = FileGetTime($File, 1)
   For $I = 0 To 2
      $ft &= $fTime[$i] & "/"
   Next
   Return StringTrimRight($Ft, 1)
EndFunc  ;<==> _File_GetDate($File)

Func _FileListToArray($sPath, $sFilter = "*", $iFlag = 0)
   Local $hSearch, $sFile, $asFileList[1]
   If Not FileExists($sPath) Then Return SetError(1, 1, "")
   If (StringInStr($sFilter, "\")) Or (StringInStr($sFilter, "/")) Or (StringInStr($sFilter, ":")) Or (StringInStr($sFilter, ">")) Or (StringInStr($sFilter, "<")) Or (StringInStr($sFilter, "|")) Or (StringStripWS($sFilter, 8) = "") Then Return SetError(2, 2, "")
   If Not ($iFlag = 0 Or $iFlag = 1 Or $iFlag = 2) Then Return SetError(3, 3, "")
   If (StringMid($sPath,StringLen($sPath),1) = "\") Then $sPath  = StringTrimRight($sPath,1); needed for Win98 for x:\  root dir
   $hSearch = FileFindFirstFile($sPath & "\" & $sFilter)
   If $hSearch = -1 Then Return SetError(4, 4, "")
   While 1
      $sFile = FileFindNextFile($hSearch)
      If @error Then
         SetError(0)
         ExitLoop
      EndIf
      If $iFlag = 1 And StringInStr(FileGetAttrib($sPath & "\" & $sFile), "D") <> 0 Then ContinueLoop
      If $iFlag = 2 And StringInStr(FileGetAttrib($sPath & "\" & $sFile), "D") = 0 Then ContinueLoop
      ReDim $asFileList[UBound($asFileList) + 1]
      $asFileList[0] = $asFileList[0] + 1
      $asFileList[UBound($asFileList) - 1] = $sFile
   WEnd
   FileClose($hSearch)
   Return $asFileList
EndFunc  ;==>_FileListToArray

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Actually this is better. Replace my _File_GetDate() function with this one.

Func _File_GetDate($File)
   $File = FileGetShortName($File)
   $fTime = FileGetTime($File, 1)
   Return StringFormat("%04d/%02d/%02d", $fTime[0], $fTime[1], $fTime[2])
EndFunc  ;<==> _File_GetDate($File)

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

This all looks too complicated. Make it easy on yourself.

#include <file.au3>
#include <date.au3>

;Root folder
$sourceFolder = @ScriptDir

;Gather files into an array
$fileList = _FileListToArray($sourceFolder, "*.*", 1)

;Loop through array
For $X = 1 to $fileList[0]
    ;Retrireve 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 one week
    If _DateDiff('d', $fDate,_NowCalc()) > 7 Then FileDelete($sourceFolder & "\" & $fileList[$X])
Next

Geo - You have to take hh:mm:ss into account too. Otherwise you will be deleting some files too early.

Edited by weaponx
Link to comment
Share on other sites

This all looks too complicated. Make it easy on yourself.

#include <file.au3>
#include <date.au3>

;Root folder
$sourceFolder = @ScriptDir

;Gather files into an array
$fileList = _FileListToArray($sourceFolder, "*.*", 1)

;Loop through array
For $X = 1 to $fileList[0]
    ;Retrireve 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 one week
    If _DateDiff('d', $fDate,_NowCalc()) > 7 Then FileDelete($sourceFolder & "\" & $fileList[$X])
Next

Geo - You have to take hh:mm:ss into account too. Otherwise you will be deleting some files too early.

I don't think so. We are just checking how many days old the file is. As a matter of fact I was just about to suggest another change in my code.

$fDate = _DateDiff("D", _File_GetDate($File), $CurrDate)
   If $fDate >= 7 Then MsgBox(0, "TEST", $File & " is " & $fDate & " day(s) old")

To

$fDate = _DateDiff("w", _File_GetDate($File), $CurrDate)
   If $fDate >= 1 Then MsgBox(0, "TEST", $File & " is " & $fDate & " week(s) old")

That will only return the number of weeks. Take a good look at the _DateDiff() function.

Edit: You are correct that %s is better than %02d though.

Here is a replacement for my func that shows the same values are returned from _DateDiff()

#Include <date.au3>
#Include <file.au3>
$CurrDate = @Year & "/" & @Mon & "/" & @Mday
$Path = "C:\logfiles\";;; Set this to whatever folder you want
$fList = _FileListToArray($Path, "*", 1)

For $I = 1 To Ubound($fList)-1
   $File = $Path & $fList[$i]
   $fDate = _DateDiff("w", _File_GetDate($File), $CurrDate)
   If $fDate >= 1 Then MsgBox(0, "TEST", $File & " is " & $fDate & " week(s) old")
 ;;^^^^^^^  Change the MsgBox() to FileDelete($File) and uncoment the next line
 ;;If @Error Then ContinueLoop
Next
Func _File_GetDate($File, $rTime = 0)
   $File = FileGetShortName($File)
   $fTime = FileGetTime($File, 1)
   If $rTime = 0 Then Return StringFormat("%s/%s/%s", $fTime[0], $fTime[1], $fTime[2])
   Return StringFormat("%s/%s/%s %s:%s:%s", $fTime[0], $fTime[1], $fTime[2], $fTime[3], $fTime[4], $fTime[5])
EndFunc  ;<==> _File_GetDate($File)

Now change $rTime to 1 and run it again.

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

The reason I wrote the _File_GetDate() function was so I can include it in one of my UDFs and call it from my _FileCompare() function. I needed it to return in the proper format for Jos' _DateDiff() function so that's where the StringFormat() works well.

Edit:

Actually I wasn't thinking straight because the right way to do $CurrDate is using StringFormat() as well

$CurrDate = StringFormat("%s/%s/%s", @Year, @Mon, @Mday)
Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Have either of you gotten yours to work? I have tried both of them and adjusted the number to go back only 1 day and it still doesn't delete anything. I have even tried to delete everything in the folder just to see if it works.

As far as the file name is concerned if they are in a format like this: specs08_121298_speclog.log, would either "specs08_??????_speclog.log" or "specs08_*_speclog.log" be correct?

I do appreciate the help, thanks guys.

Link to comment
Share on other sites

I'm pretty new to the AutoIT forum. So I'm never quite sure if I understand what people are trying to accomplish... But... What I've seen in this post looks like quite a lot of "complicated" processing... :D Why not use a simple, one-line FORFILES command via a CMD BATCH process to delete those files? It handles "recursives" for multiple directory processing (if you need it). For example, to delete all PDF files on the S: drive (and sub folders) that are more than 30-days old (based on the file modified date) use:

forfiles -p "s:\" -s -m *.pdf -d -30 -c "cmd /C dir @FILE"

In the example above, I coded "dir" - which, obviously, once you tested it and verified it picked the files you wanted should be changed to "del".

Link to comment
Share on other sites

I'm pretty new to the AutoIT forum. So I'm never quite sure if I understand what people are trying to accomplish... But... What I've seen in this post looks like quite a lot of "complicated" processing... :D Why not use a simple, one-line FORFILES command via a CMD BATCH process to delete those files? It handles "recursives" for multiple directory processing (if you need it). For example, to delete all PDF files on the S: drive (and sub folders) that are more than 30-days old (based on the file modified date) use:

forfiles -p "s:\" -s -m *.pdf -d -30 -c "cmd /C dir @FILE"

In the example above, I coded "dir" - which, obviously, once you tested it and verified it picked the files you wanted should be changed to "del".

The thing is, there is hundreds/thousands of files in the folder, they are mostly log files but there are plenty of them there that I do not want to delete that are over 7 days old. Basically there are 2 specific files but many varying filenames that I only want 7 days worth at any given time. The variation is in the middle of the filename.

Example:

specs08_121298_speclog.log

specs08_121299_speclog.log

But there will be files like spec08-1_121390_speclog.log that I would like to keep. So I can not just simply remove all *.log files that are 7 days old or older.

Link to comment
Share on other sites

So are you able to define the exact "format" of the files you DO want to delete using wildcards? For example, could you use something like this:

forfiles -p "s:\" -s -m "specs08_??????_speclog.log" -d -30 -c "cmd /C dir @FILE"
Edited by UmmDoughnuts
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...