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

Jan 26, 2014 2:06 PM in response to kashlan

The system I use is a folder for each year then subfolders for the full creation dates under the year folder. The files are then stored in the subfolder of the date the file was created. I can get it to create both a year folder and a creation date folder but the creation date folder is another folder in the The Container not as a subfolder of the year folder. How can I get it to work?

Jan 26, 2014 2:19 PM in response to red_menace

The system I use is a folder for each year then subfolders for the full creation dates under the year folder. The files are then stored in the subfolder of the date the file was created. I can get it to create both a year folder and a creation date folder but the creation date folder is another folder in the The Container not as a subfolder of the year folder. How can I get it to work?

Jan 26, 2014 3:42 PM in response to Mike Maas

You just need to insert another folder creation step, for example:

  ...     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       set theYear to text 1 thru 4 of theDate       try -- check if the year folder exists         get ("" & theContainer & theYear) as alias       on error -- make a new year folder         make new folder at theContainer with properties {name:theYear}       end try       set yearFolder to the result                  try -- check if the date folder in the year folder exists         get ("" & yearFolder & theDate) as alias       on error -- make a new date folder         make new folder at yearFolder with properties {name:theDate}       end try       -- duplicate anItem to the result       move anItem to the result   ...

Jan 26, 2014 9:21 PM in response to red_menace

Thanks,


I am trying to get it to work where I can just drop a folder with the file I want sorted and move into the application icon for Automator application, and it does its thing. I made the first Automator action Get Folder Contents (removing the Get Folder Contents) and made the first line of the script "on run". got a message "The action “Run AppleScript” encountered an error. Check the actionʼs properties and try running the workflow again."


Being an applescript novice I an lost. Can you help? Thanks

Jan 27, 2014 7:07 AM in response to Mike Maas

You don't need to add another "on run" - the posted script (with the previous modification) is all you need to place into the Run AppleScript action, replacing its default script. Saving the workflow as an application will allow you to use it as a droplet (items dropped onto the application will be passed to the workflow), so you don't need other actions in order to get items. When using your workflow like that, all you need to add is a Get Folder Contents action to get files from any folders dropped, and possibly a Filter Finder items action if you want to filter the types of files passed on.


The workflow can still be run from Automator, in that case you just need to temporarily add another action at the beginnning to get some input items. Automator has a log at the bottom of the workflow section - clicking on the error should expand it to tell you what the specific error is, instead of the generic "encountered an error" message.

Jan 30, 2014 4:35 PM in response to kashlan

This thread is about one of the most searched for tasks.


I've read thru the entire 4 pages of the post from 2009 to today.


As a newcomer to the thread, it is disjointed and confusing.


Someone should post the step-by-step process to perform this most basic of tasks/requests, from start to finish.


A video would be gold! 🙂


I gotta tell ya, I'm ok playing with Automator, but when it comes to Applescript AND Automator... I'm lost.


As the title of the post says: "Relocating files based on creation date" - at this point all we need is a good tutorial of the steps needed to accomplish this.


Let's wrap this up with the ultimate step-by-step instruction, for us novices as well as experts wanting to save some time.


Thanks in advance!


~brian

Jan 30, 2014 5:27 PM in response to hotsaucedaily

Yes, and this is the main reason for people to start a new topic (referring to a related one if needed), but it doesn't usually happen that way. Setting the forum view preferences to threaded should help organize various threads, but that also doesn't work very well if people reply to the wrong person or the original post.


Some of the formatting got lost when the forums were updated, so some of those old replies include some HTML which the AppleScript Editor will not like, but the answer would appear to be my first reply back in 2009 (although the OP didn't mark any reply as helpful or the answer). Pretty much everything else is a "hey, it's close, but I want it to do this" kind of thing, so those threads contain the modifications for that kind of thing.


The Run AppleScript action is what does all of the work, and replaces the default script - the rest of the workflow just gets the files to pass on to it, so the workflow is just something like:


  1. Ask for FInder Items {Type: Folders} -- can also get files
  2. Get Folder Contents (be careful with getting subfolders - this action will go into packages)
  3. Run AppleScript -- paste in the original script (minus the HTML) or the various tweaks posted

Jan 30, 2014 5:54 PM in response to red_menace

@red_menace - I get what you are saying about topics, threads, the formatting from the old forums, etc.


You obviously are very well versed in this topic, and have been hugely helpful to many people. But I'm afraid, in your knowledge, you miss my point. I need hand-holding from Point A to Point Z. IOW, a simple, step-by-step set of instructions to get the job done. Without having to sort thru 5 years of posts in one thread.


Pretend this is the very first post, and share your answer that I and others can understand.


Run AppleScript -- paste in the original script (minus the HTML) or the various tweaks posted

That is just what I don't need. No offense, but it just adds to my confusion. "Various tweaks"? That's great for other options that some may need, but to stick to the original topic, some of us are just looking for a way to "relocate files based on creation date".


Hopefully someone in this thread (you?) will just post a simple tutorial in its entirety.


Again, thanks for your help.

Feb 5, 2014 2:55 PM in response to red_menace

Thanks so much this script has really helped me. However is it possible to get the script to create folders based on the name YYYY_MM_DD rather than YYYY-MM-DD? The only reason is my old camera software on my Windows PC did it this way so it would make things a lot neater if all the folders were the same naming style on my external hard drive.


Thanks so much once again.

Feb 5, 2014 5:11 PM in response to Mike9586

The name is just the first 10 characters of an ISO date/time string, which is in the format YYYY-MM-DDThh:mm:ss

set theDate to text 1 thru 10 of (creation date of anItem as «class isot» as string)


So you can replace that statement with something else to tear the date string apart and rearrange it however you want, for example:

tell (creation date of anItem as «class isot» as string)   set theDate to text 1 thru 4 & "_" & text 6 thru 7 & "_" & text 9 thru 10 end tell

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.