Hi All,
Developing a script to clean out folders of redundant files from a database. I have a script that works only that there are ~7000 folders containing entries that my script is searching through. Is there are a way to set the folders to search through to be limited to a variable?
Currently the script looks like:
tell application "Finder"
set DBLoc to (choose folder "Where are the files for cleaning out?")
with timeout of 600 seconds
set StartTime to (time of (current date))
set DBFldrs to (every folder of DBLoc whose size is greater than 1024)
set FileCount to 0 as number
repeat with aFldr in DBFldrs
set Rfiles to (every file of aFldr whose modification date is less than expireddate)
set TiffCount to the count of Rfiles
if TiffCount is greater than 0 then
repeat with thisFile in Rfiles
set i to thisFile as alias
set moddate to the (modification date of (info for i))
if moddate is less than (expireddate as date) then
delete i
set FileCount to (FileCount + 1)
end if
end repeat
end if
if FileCount is greater than FileLimit then
exit repeat
-- Thanks themacgeek MacScripter
end if
end repeat
set EndTime to (time of (current date))
end timeout
end tell
Nb. My current script has a timeout of 600 (10 min), but it’s still not enough. Files are residing on a Windows Server, script is searching an SMB share.
This generates a list of folders that contains files, but it looks through all 7000 folders to build the list. Next I have a sub-routine which deletes files from the folders that are older than a pre-determined date.
Is there syntax that will allow me to limit the number of folders added to the initial folder list?
Something maybe like this:
set fldrCount to text returned of (display dialog "How many folders of files do you want to process?" default answer "10")
set DBFildrs to (first fldrCount folders of DBLoc whose size is greater than 1024).
Thus limiting the initial number of folders that are set for searching files.
Thanks in Advance.
Matt.