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

Dec 8, 2013 11:23 AM in response to red_menace

red_menace-- thanks so much for this script. I'm new to Automator and AppleScript. In fact, yours is the first I've used and it was only this week. Very useful, so thanks again.


Wanted to share some extra info with folks...


My case is that I had a bunch of photos on discs. Using an old Win 2k system (where I have a disc drive as my MacBook Air doesn't) to copy files over to my new Synology NAS.


When one does so, the files are (a) in a locked state and (b) use the date that you copied them as a Created date rather than the date they were actually created. The Created date is actually reflected in the Modified date. (Side note: if one copies a file locally (e.g., to my MacBook Air), then the Created date is restored correctly.)


Modified your script slightly to use the Modified date rather than the create date. That was easy. (theDate = modDate). Next, I found this script to unlock all files in a directory:


set fileSample to choose folder with prompt "Choose a folder to process."

set folderName to name of (info forfileSample)

tell application "Finder" to set theFiles to files of folder fileSample


tell application "Finder"

repeat with oneFile in theFiles

set lockedStatus to locked of oneFile

if locked of oneFile is true then

set locked of oneFile to false

end if

end repeat

end tell


Run this first and problem (a) solved. Then run your script (slightly modifed), and problem (b) solved.


There's probably a way I can do this in onl fell swoop (in a single Automator job) and also probaly a way for me to change the create date of a file to the modifed date (to correct this little issue). If there's any input from anyone on either of these, would be greatly appreciated.


If not, no big deal. For now, this is good enough as it gets the files in the right directlry, and my time is tight to get this job done.









Dec 8, 2013 11:44 AM in response to red_menace

Worked like a charm. Thanks so much.


Though I'm bit of a dummy with Applescript and I am trying to not having to choose the folder I am moving to and set it to my Pictures folder. I tried the following many times...


set theContainer to "/Users/Dharma/Pictures" -- a Finder path to a destination folder, or missing value for the source folder


It still asks me to choose the folder. What am I doing wrong?


Regards

Dharma

Dec 24, 2013 12:27 PM in response to red_menace

This script was running beautifully prior to Mavericks, but now it doesn't work for me at all. Here's what I have, pulled from Automator:


-----------------------------------


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 itemAnItem

else -- move to the source folder

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

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


makenewfolderatTheContainerwith 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



ShowSkippedAlertforSkippedItems

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

end run



to ShowSkippedAlertforSkippedItems


(*

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'stext item delimiters} to {AppleScript'stext item delimiters, return}

set {SkippedItems, AppleScript'stext 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




--------------------------------------------

The above is set to Folder Action for a specific folder. When I move files into the designated folder, nothing happens, despite this script being set as a Folder Action in Finder. When I run it in Automator it happily reports that the workflow is completed. But nothing actually happens in Finder -- the files haven't moved or anything.


I have no script expertise at all (obviously) but was so grateful to have found this script back when it was working. Any help would be appreciated.

Dec 28, 2013 11:36 AM in response to kashlan

Hi all -

If anyone isn't comfortable with AppleScript, another way is to leverage the existing exiftool executable. After you incorporate this magic into your automator workflow, it will be immune to OS updates since we will be running exiftool as a script.


Big thanks to Phil Harvey for making this such a powertool in the world of thousands of image files.

http://www.sno.phy.queensu.ca/~phil/exiftool/


To see the tool in action, insert your SD card on your Mac, open a command terminal and :

$ cd /Volumes/[your_cardname]

$ exiftool -o . -r -P '-directory<datetimeoriginal' -d ~/Pictures/%Y/%m .


What this little gem will do is recursively copy all the images from an SD card into a folder structure under ~/Pictures/2013/12 or whatever the exif data reveals for the image(s). If you want more/less granularity, change the %Y/%m to be whatever you need.


Go here for details on the date format: http://owl.phy.queensu.ca/~phil/exiftool/filename.html


Hope someone enjoys this as much as I did.

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 ID.