Jump to content
Sign in to follow this  

_FileListToArrayRec - delete sub folders in a specified depth

Recommended Posts

Hi everyone, sorry to re-post a portion of a code that I asked about only a short while ago, but I'm still learning the ropes and trying to make the script work.

The main goal of my script it to delete folders that are older than 90 days but only in a certain depth.

So for example, if this is the path: "c:userstest" - I only need to check the date modified of the folders under "test" directory and delete those folders that are older than 90 days.

By using _FileListToArrayRec and -2 Negative integer - I get an array of the subfolders in the specified depth that I require. But I also get back everything else (-1 depth and 0 depth)

_FileListToArrayRec ($sRoot, "*", 2, -2, 2)

So the array I get is: 




My question would be - how do I only end up with the -2 depth (c:userstest) so that I can only check the date modified of those folders and delete them?


Share this post

Link to post
Share on other sites

could you post the entire code plz ?

My video tutorials : HERE ( In construction )  || My Discord : https://discord.gg/S9AnwHw

How to Ask Help ||  UIAutomation From Junkew || WebDriver From Danp2 || And Water's UDFs in the Quote


 Water's UDFs:
Active Directory (NEW 2018-10-19 - Version - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki

ADO - Wiki


Share this post

Link to post
Share on other sites

Sure: (It is based on a script from the forum - ?do=embed' frameborder='0' data-embedContent>)

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

; ***** Create local logs
$log = FileOpen (@ScriptDir & "\masterlog.log",2+256)
_FileWriteLog ($log,"*********************STARTING OPERATIONS*********************")

; put the root in a variable
$sRoot = (@ScriptDir)

; Retrieve a list of all the folders in $sRoot, and store them as an array in $aList
Global $aList = _FileListToArrayRec ($sRoot, "*", 2, -2, 2) ; _FileListToArray("path" [, "Filter" [, Flag]])
; Look at what _FileListToArray() puts into $aList

; This is a loop that runs from 1 to the number of items listed in the first element of the returned array
For $i = 1 To $aList[0]
; For each folder, get the modified date/time and store its individual parts in array $aDate
$aDate = FileGetTime($sRoot & "\" & $aList[$i], 0, 0) ; FileGetTime("filename" [, option [, format]])

; Look at what FileGetTime() puts into $aDate

; Build the properly formatted date string for _DateDiff()'s needs
$sDate = $aDate[0] & "/" & $aDate[1] & "/" & $aDate[2] ;0 index stores the year, 1 index stores month, 2 index stores day

; Look at what we made into $sDate
;msgbox(0,"Check Output", $sDate)

; Use _DateDiff() to see if the difference is greater than 90 days, and if it's true, then delete (for now just log) the folder and all its subfolders
If _DateDiff("D", $sDate, _NowCalcDate()) > 0 Then _FileWriteLog ($log,$sRoot & "\" & $aList[$i] & "  " & "| Date Modified: " & $sDate, 1)
_FileWriteLog ($log,"*********************Script Completed Successfully*********************")

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  

  • Create New...