Pretty new scripter so sorry if this is lame. As part of a larger script, i’m trying to delete old files out of a folder. I thought this would work but it errors out because, assumedly, it’s deleting the very files it’s using to count. i can’t imagine this task isn’t a pretty common one though so i was hoping someone out there had a solution.
tell application "Finder"
set filecount to count of files
repeat with i from 1 to filecount
set currentfile to item i
if (current date) - (modification date of currentfile) is greater than 172800 then
any help or general mocking of my ignorance is more than welcome. thanks.
You may not get the results you are looking for with your code because you count the files but then you reference the items. Items encompass both files and folders. You’re better off first getting the file list and then iterating through that. Also, you’ll save some time by getting the current date only once and assigning it to a variable: