Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Sort files into subfolders based on date added Desktop
There are many published methods to put files in named folders based on date created or modified, but this one puts them in corresponding folders based on the date the file was added to the folder, similar to the sorting option for stacks in the Dock -- I use this to organize my Downloads folder.

The following AppleScript works by exploiting the HFS+ inode table, and retrieves the date which the file's name was added to the directory tree, regardless of when it was previously modified or created in other locations.
tell application "Finder"
    set mifold to choose folder
    set filelist to every file of mifold as list
    set foldlist to every folder of mifold as list
    repeat with i from 1 to number of items in filelist
        set subj to item i of filelist as alias
        set epoch to (do shell script "stat -f \"%B\" " & (quoted form of (POSIX path of subj)))
        set caldate to do shell script ("date -r " & epoch & " \"+%Y-%m-%d\"")
        
        if not (exists folder caldate of mifold) then
            make new folder at mifold with properties {name:caldate}
        end if
        try
            (* try ignores errors from locked files *)
            move file subj to folder caldate of mifold
        end try
    end repeat
    repeat with j from 1 to number of items in foldlist
        set subj to item j of foldlist as alias
        if name of subj does not start with "200" then
            set epoch to (do shell script "stat -f \"%B\" " & (quoted form of (POSIX path of subj)))
            set caldate to do shell script ("date -r " & epoch & " \"+%Y-%m-%d\"")
            if not (exists folder caldate of mifold) then
                make new folder at mifold with properties {name:caldate}
            end if
            try
                (* try ignores errors from locked items *)
                move folder subj to folder caldate of mifold
            end try
            
        end if
    end repeat
end tell
It could probably use some optimization, so feel free to make suggestions if you're an AppleScript geek!

[robg adds: This works as described, at least on the folders I tested it with. Note there's no going back, of course, so if you run the script, you'd have to manually restore the flat folder structure if you change your mind. A couple of other hints in this category include organizing the Downloads folder by download date (which changes the files' modifications times to re-sort them) and using Hazel to sort items in folders (among its other features).]
    •    
  • Currently 2.13 / 5
  You rated: 4 / 5 (8 votes cast)
 
[13,386 views]  

Sort files into subfolders based on date added | 3 comments | Create New Account
Click here to return to the 'Sort files into subfolders based on date added' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Sort files into subfolders based on date added
Authored by: dougeverly on May 05, '09 08:25:26AM
Relatedly, see also ForlderOrg at this tip http://www.macosxhints.com/article.php?story=20031103145431293 which I submitted forever ago. http://homepage.mac.com/dougeverly/folderorg.html

[ Reply to This | # ]
or use some shell commands
Authored by: PatrickS on May 05, '09 10:24:32AM
Shell commands to do the same

for f in *; do
    dir=$(stat -f%SB -t%Y-%m-%d "$f")
    echo $f '->' $dir
    [ -d "$dir" ] || mkdir "$dir"
    mv "$f" "$dir"/
done
Replace the B in %SB by m for the last modification date of the file.

[ Reply to This | # ]
Sort files into subfolders based on date added
Authored by: osxpounder on May 06, '09 09:10:48AM

Is this script meant to be a Folder Action, running automatically every time a file appears in its folder?



[ Reply to This | # ]