Howdy all-
I’m having some trouble automating the creation of a file structure for video clips and I wonder if someone here can help. I’ve tried to use automator, but I’m a newbie and not having much luck.
I recently had a hard drive crash and needed to recover data from the drive. Unfortunately, I was only able to retrieve the clips alone… 474 of them
This is what the file structure is supposed to look like:
A020_0213N4.RDM (folder) > A020_C001_0213N4.RDC (folder) > A020_C001_0213N4_001.R3D (file)
All I have are the “.R3D” files. I would like to automate the process of creating the folders and naming them. As you can see, each folder has a similar name as the R3D file, but not exactly the same.
Short version of what I’m trying to do:
Create a folder named after the .R3D file name minus the last 4 characters (_001) and add “.RDC” extension.
Place .R3D file(s) in that folder.
Create a folder named after .RDC folder name minus 5th, 6th, 7th, 8th, and 9th characters (_C001) and add “.RDM” extension.
Place all .RDC folders starting with A020 into .RDM folder starting with A020_0213
Long version of what I’m trying to do:
The camera is what generates this file structure. “A020” is the “reel” name. Each time the camera is reloaded with new media (a hard drive or CF card) it will sequentially rename the “reel” number. For instance, the next one would be called “A021”.
“C001” is the clip number and “0213N4” is the date with a couple random characters at the end. The “001” at the end of the R3D file is only if the camera records more than 2 gigs in the clip. If it exceeds 2 gigs, the camera will generate a new clip in the same folder with “002” at the end of the file name.
As you may have guessed, there may be multiple RDC folders in a RDM folder. For instance A020_C001_0213N4.RDC, A020_C002_0213N4.RDC , A020_C003_0213N4.RDC and so on. Likewise, there are often multiple R3D files in a RDC folder so I need my automation process to be smart enough to base everything on the file name of the R3D file.
I am not an Automator expert, but have some experience with AppleScript. So I wrote you a script to get you started, please see the code below.
The script will ask you to choose a folder containing all the R3D files. It will then process the found R3D files, creating the folder structure as described by you and moving the R3D files into the subfolders.
Please test it first on some sample files before batch processing all 474 R3D files.
I commented the code, so you can check if it really fits your needs.
Hope it helps.
Best regards from snowy Berlin,
Martin
property mytitle : "R3D2Folders"
-- I am called when the user opens the script with a double click
on run
try
-- this is the folder where the R3D files are located
set basefolder to choose folder with prompt "Where is the folder containing the the R3D files?"
-- getting a list of all R3D files in that chosen folder
tell application "Finder"
set r3dfiles to (every file in basefolder whose name ends with ".R3D") as alias list
end tell
-- no R3D files found :(
if r3dfiles is {} then
set errmsg to "The chosen folder does not contain any R3D files (*.R3D)."
my dsperrmsg(errmsg, "--")
return
end if
-- processing found R3D files
repeat with r3dfile in r3dfiles
set r3dfileinfo to (info for r3dfile)
set r3dfilename to (name of r3dfileinfo) as text
-- A020_C001_0213N4_001.R3D -> {"A020", "C001", "0213N4", "001.R3D"}
set r3dfilenameparts to my gettxtitems("_", r3dfilename)
-- name of the RDM folder
set rdmfoldername to ((item 1 of r3dfilenameparts) & "_" & (item 3 of r3dfilenameparts) & ".RDM") as text
-- name of the RDC folder
set rdcfoldername to (item 1 of r3dfilenameparts & "_" & item 2 of r3dfilenameparts & "_" & item 3 of r3dfilenameparts & ".RDC") as text
-- complete subfolder path
set subfolderpath to ((basefolder as text) & rdmfoldername & ":" & rdcfoldername & ":") as text
-- cretaing the folder structure if needed
if not my itempathexists(subfolderpath) then
set command to "mkdir -p " & quoted form of POSIX path of subfolderpath
do shell script command
end if
-- moving the R3D file into its subfolder
tell application "Finder"
move r3dfile to (subfolderpath as alias)
end tell
end repeat
on error errmsg number errnum
if errnum is not equal to -128 then
my dsperrmsg(errmsg, errnum)
end if
end try
end run
-- I am returning the text items of a text separated by the given delimiter
on gettxtitems(delim, txt)
set olddelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to {delim}
set txtitems to text items of txt
set AppleScript's text item delimiters to olddelims
return txtitems
end gettxtitems
-- I am indicating whether a given item path exists
on itempathexists(itempath)
try
set itemalias to itempath as alias
return true
on error
return false
end try
end itempathexists
-- I am displaying error messages to the user
on dsperrmsg(errmsg, errnum)
tell me
activate
display dialog "Sorry, an error occurred:" & return & return & errmsg & " (" & errnum & ")" buttons {"OK"} default button 1 with icon stop with title mytitle
end tell
end dsperrmsg