Last Updated: February 25, 2016
·
514
· chauvd

File Info from Directory

I found myself writing a script to intelligently clean up my Downloads folder periodically. I wanted to learn a bit of AppleScript while at the same time affording myself the efficiency and productivity to get it done quickly. The 'delete' operation in AppleScript only moves the selected file to Trash and requires a subsequent call to 'Empty trash'. I therefore wanted switched course and decided to get the file info of all the files in the directory, appending them to a list which I could later use to execute a shell call using 'rm'.

on findOldFiles(directory)
    set the files_list to list folder directory without ¬
    invisibles
    repeat with i from 1 to the (count of items) in the ¬
    files_list
        set current_file to item i of the files_list
        set file_info to (info for directory & "/" & ¬
        current_file)
    end repeat
end findOldFiles

This is the quick function I came up with after some research that can be used further to filter out files based on some info attribute and placed into a list.