Created
January 9, 2015 03:21
-
-
Save majosystems/e341f590e57d00c7911f to your computer and use it in GitHub Desktop.
デスクトップやダウンロードのファイル整理用
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
to zero_pad(num, slength) | |
set maxlnum to "0000000000" & (num as text) | |
set ret_str to text ((length of maxlnum) - (slength - 1)) thru -1 of maxlnum | |
return ret_str | |
end zero_pad | |
to datef(d) | |
set yyyy to zero_pad(year of d, 4) | |
set mm to zero_pad(month of d as number, 2) | |
set dd to zero_pad(day of d, 2) | |
return yyyy & "-" & mm & "-" & dd | |
end datef | |
on adding folder items to thisFolder after receiving theseItems | |
tell application "Finder" | |
set fileList to every file of thisFolder whose name extension ≠ "download" as list | |
set folderList to every folder of thisFolder as list | |
set docfolder to path to documents folder as alias | |
set docfolder_path to docfolder's POSIX path | |
set basePath to docfolder_path & "backup/" & name of thisFolder & "/" | |
set okuriFolder to POSIX file basePath as alias | |
repeat with i from 1 to number of items in fileList | |
set curItem to item i of fileList as alias | |
set curItemName to curItem's name | |
set createDate to curItem's modification date | |
set createDate to my datef(createDate) | |
set todayDate to my datef(current date) | |
if not (createDate = todayDate) then | |
if not (exists folder createDate of okuriFolder) then | |
make new folder at okuriFolder with properties {name:createDate} | |
end if | |
try | |
move file curItem to folder createDate of okuriFolder | |
end try | |
end if | |
end repeat | |
end tell | |
end adding folder items to |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment