You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Relocating files based on creation date

Hello,

I have a folder full of hundreds of Video clips. I am interested in a script that will

1. look at the files sequentially
2. For each file read the creation date
3. If a Folder with that creation date does not exist, create a folder with that creation date (YYYY-MM-DD)
4. Move the file to the folder with the file's creation date

I've never used automator. Is this easy to do using that program?

The reason I want to do this is to avoid having to manually re-organize the videos by date, if I were to import the contents of the existing folder of video clips into iMovie.

Appreciate any input you can provide.

Thanks.

MacBook Pro, Mac OS X (10.5.7)

Posted on Aug 23, 2009 7:28 AM

Reply
74 replies

Jun 11, 2013 7:30 AM in response to red_menace

red_menace, THANK YOU for taking the time to put this up and to reply to so many people's questions!


I'm very green when it comes to Automator and AppleScript. They intimidate me. I was able to use your instructions and this is ALMOST doing what I'd like it to do.


Could you tell me what I need to change if I want don't want to choose the folders where the files are originating from and where they are going to every time?


For example, I will have a folder "A" and whenever files are dropped into folder "A", I want them to automatically get moved and organized into date folders within folder "B" without any prompts. Is this possible? If so, please let me know how to do it!


Thank you!!!

Jun 11, 2013 8:13 PM in response to rdarton

You can create a Folder Action workflow, which will get the items added to the folder, and set a specific destination path in TheContainer variable, for example:

setTheContainerto"Macintosh HD:Users:you:someParentFolder:someFolder:"


You can use a single choose folder statement in the AppleScript Editor and look at the result log to see what your particular path should look like - if you use an invalid path, the script will ask you to choose the folder.

Oct 14, 2013 10:03 AM in response to Old Man George

Give this a try. AppleScript comments are delimited by -- or # for an end-of-line, and (* *) for multiple lines.

on run {input, parameters} -- create folders and move   (*     make new folders from file creation dates (if needed), then move document files into their respective new folders     if no container is specified (missing value), the new folder will be created in the containing folder of the item     if the container is not a valid path (and not missing value), one will be asked for       input: a list of Finder items (aliases) to move       output: a list of the Finder items (aliases) moved   *)     set output to {}   set skippedItems to {} -- this will be a list of skipped items (errors)   set theContainer to "" -- a Finder path to a destination folder, or missing value for the source folder     if theContainer is not missing value then try -- check the destination path     theContainer as alias   on error     set theContainer to (choose folder with prompt "Where do you want to move the items?")   end try     tell application "Finder" to repeat with anItem in the input -- step through each item in the input     if theContainer is not missing value then -- move to the specified folder       set {class:theClass, name:theName, name extension:theExtension} to item anItem     else -- move to the source folder       set {class:theClass, name:theName, name extension:theExtension, container:theContainer} to item anItem     end if     if theClass is document file then try -- just documents       set theDate to text 1 thru 10 of (creation date of anItem as «class isot» as string) -- YYYY-MM-DD       try -- check if the target folder exists         get ("" & theContainer & theDate) as alias       on error -- make a new folder         make new folder at theContainer with properties {name:theDate}       end try       -- duplicate anItem to the result       move anItem to the result       set the end of output to (result as alias) -- the new file alias     on error -- permissions, etc       -- set the end of skippedItems to (anItem as text) -- the full path       set the end of skippedItems to theName -- just the name     end try   end repeat     showSkippedAlert for skippedItems   return the output -- pass the result(s) to the next action end run to showSkippedAlert for skippedItems   (*     show an alert dialog for any items skipped, with the option to cancel the workflow       parameters - skippedItems [list]: the items skipped       returns nothing   *)   if skippedItems is not {} then     set {alertText, theCount} to {"Error with AppleScript action", (count skippedItems)}     if theCount is greater than 1 then       set theMessage to (theCount as text) & space & " items were skipped:"     else       set theMessage to "1 item was skipped:"     end if     set {tempTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, return}     set {skippedItems, AppleScript's text item delimiters} to {skippedItems as text, tempTID}     tell application "System Events" to if button returned of (display alert alertText message (theMessage & return & skippedItems) buttons {"Cancel", "OK"}) is "Cancel" then error number -128   end if   return end showSkippedAlert

Oct 14, 2013 10:25 AM in response to Old Man George

Below is a copy/paste directly from my AppleScript editor. Looks like it might be the same as Old Man George's script but I didn't check line for line. Worked great for me. Copy/paste:



on run {input, parameters} -- create folders and move

(*

make new folders from file creation dates (if needed), then move document files into their respective new folders

if no container is specified (missing value), the new folder will be created in the containing folder of the item

if the container is not a valid path (and not missing value), one will be asked for

input: a list of Finder items (aliases) to move

output: a list of the Finder items (aliases) moved

*)


set output to {}

set SkippedItems to {} -- this will be a list of skipped items (errors)

set TheContainer to "" -- a Finder path to a destination folder, or missing value for the source folder


if TheContainer is not missing value then try -- check the destination path

TheContainer as alias

on error

set TheContainer to (choose folder with prompt "Where do you want to move the items?")

end try


tell application "Finder" to repeat with AnItem in the input -- step through each item in the input

if TheContainer is not missing value then -- move to the specified folder

set {class:TheClass, name:TheName, name extension:TheExtension} to item AnItem

else -- move to the source folder

set {class:TheClass, name:TheName, name extension:TheExtension, container:TheContainer} to item AnItem

end if

if TheClass is document file then try -- just documents

set TheDate to text 1 thru 10 of (creation date of AnItem as «class isot» as string) -- YY_MM_DD

try -- check if the target folder exists

get ("" & TheContainer & TheDate) as alias

on error -- make a new folder

make new folder at TheContainer with properties {name:TheDate}

end try

-- duplicate AnItem to the result

move AnItem to the result

set the end of output to (result as alias) -- the new file alias

on error -- permissions, etc

-- set the end of SkippedItems to (AnItem as text) -- the full path

set the end of SkippedItems to TheName -- just the name

end try

end repeat


ShowSkippedAlert for SkippedItems

return the output -- pass the result(s) to the next action

end run



to ShowSkippedAlert for SkippedItems

(*

show an alert dialog for any items skipped, with the option to cancel the workflow

parameters - SkippedItems [list]: the items skipped

returns nothing

*)

if SkippedItems is not {} then

set {AlertText, TheCount} to {"Error with AppleScript action", count SkippedItems}

if TheCount is greater than 1 then

set theMessage to (TheCount as text) & space & " items were skipped:"

else

set theMessage to "1 " & " item was skipped:"

end if

set {TempTID, AppleScript's text item delimiters} to {AppleScript's text item delimiters, return}

set {SkippedItems, AppleScript's text item delimiters} to {SkippedItems as text, TempTID}

if button returned of (display alert AlertText message (theMessage & return & SkippedItems) ¬

alternate button "Cancel" default button "OK") is "Cancel" then error number -128

end if

return

end ShowSkippedAlert

Relocating files based on creation date

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.