Jump to content

_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: 

c:

c:users

c:userstest

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?

Thanks!

Link to comment
Share on other sites

could you post the entire code plz ?

My video tutorials : ( 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

Spoiler

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

ADO - Wiki

 

Link to comment
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
_ArrayDisplay($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
;_ArrayDisplay($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)
Next
_FileWriteLog ($log,"*********************Script Completed Successfully*********************")
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...