It’s funny to see comments which don’t match what was described in the original question.
Original contents:
[format]- Parent Folder
- 100EOS5D --Contains .CR2 raw image files. May contain .JPG files depending on camera settings. (Numbers change based on when the photos were taken)
- 101EOS5D
- 102EOS5D[/format]
New comment:
[format]Can we add a clause that tells it to skip folders that don’t start with EOS5D so that it doesn’t affect any other folders other than image folders?[/format]
And of course when I look at the screenshot there is no folders whose name resemble to 100EOS5D, 101EOS5D
But this is not sufficient.
I carefully wrote:
[format]CAUTION : I defined myRaw as “.NEF” because it’s what is used by my Nikon camera.[/format]
It’s clear that you didn’t took care of that so that the script doesn’t recognize your abcd.CR2 files.
From my point of view, the only true problem is that I failed to insert a slash between a foldername and a filename in two instructions.
Honestly, I was unable to guess that you were storing so many different things in the folder to treat.
What is written in your message:
[format]My goal is to be able to drag folders from my camera’s memory card into a parent folder. Then run a script and have the folders renamed appropriately, move the .CR2 and .JPG files from the camera into a new subfolders based on extension, and create another new empty folder.[/format]
was far from letting think that there is such a mess in the folder to treat.
I took care to filter folder to don’t treat the folders treated by a first use.
If I was tempted to filter the source folder, according to your description, I would have checked that the folder names were beginning with a group of three digits, not by “EOS”.
Here is an edited version:
on run
set mainFolder to choose folder
my germaine(mainFolder)
end run
on open sel
set mainFolder to item 1 of sel
my germaine(mainFolder)
end open
on germaine(mainFolder)
set myRaw to ".NEF" # IT'S YOUR DUTY TO PUT YOUR NAME EXTENSION HERE !
tell application "System Events"
set theFolders to folders of mainFolder
set knt to 0
repeat with aFolder in theFolders
tell me to set POSIXsource to POSIX path of aFolder
if POSIXsource does not end with "/" then set POSIXsource to POSIXsource & "/"
set origName to name of aFolder
if origName contains "EOS5D" then
set knt to knt + 1
set kntPadded to text -2 thru -1 of ((1000 + knt) as text)
set newName to "Position_" & kntPadded
try
make new folder at end of mainFolder with properties {name:newName}
end try
set newRaw to newName & "_Raw"
try
make new folder at end of folder newName of mainFolder with properties {name:newRaw}
end try
set POSIXRaw to my getPOSIXPath((mainFolder as text) & newName & ":" & newRaw)
set theNames to (name of every file of aFolder whose visible is true)
set beurk to theNames as text
if (beurk contains ".jpg") or beurk contains ".jpeg" then
set newJpg to newName & "_Jpg"
try
make new folder at end of folder newName of mainFolder with properties {name:newJpg}
end try
set POSIXJpg to my getPOSIXPath((mainFolder as text) & newName & ":" & newJpg)
end if
repeat with aName in theNames
if aName ends with myRaw then
tell me to do shell script "mv " & quoted form of (POSIXsource & aName) & space & POSIXRaw # EDITED
else if (aName ends with ".jpg") or (aName ends with ".jpeg") then
tell me to do shell script "mv " & quoted form of (POSIXsource & aName) & space & POSIXJpg # EDITED
end if
end repeat
delete aFolder
end if # origname.
end repeat
end tell
end germaine
on getPOSIXPath(hfsPath)
return quoted form of POSIX path of hfsPath
end getPOSIXPath
Took care of this instruction:
set myRaw to ".NEF" # IT'S YOUR DUTY TO PUT YOUR NAME EXTENSION HERE !
I can’t test with your raw format because such files aren’t available on my machine.
The history is :
tell application "Script Editor"
choose folder
--> alias "SSD 500:Users:yvankoenig:Desktop:parent:"
end tell
tell application "System Events"
get every folder of alias "SSD 500:Users:yvankoenig:Desktop:parent:"
--> {folder "SSD 500:Users:yvankoenig:Desktop:parent:100EOS5D:", folder "SSD 500:Users:yvankoenig:Desktop:parent:101EOS5D:", folder "SSD 500:Users:yvankoenig:Desktop:parent:101NCD80:"}
get POSIX path of folder "SSD 500:Users:yvankoenig:Desktop:parent:100EOS5D:"
--> "/Users/yvankoenig/Desktop/parent/100EOS5D"
get name of folder "SSD 500:Users:yvankoenig:Desktop:parent:100EOS5D:"
--> "100EOS5D"
make new folder at end of alias "SSD 500:Users:yvankoenig:Desktop:parent:" with properties {name:"Position_01"}
--> folder "SSD 500:Users:yvankoenig:Desktop:parent:Position_01:"
make new folder at end of folder "Position_01" of alias "SSD 500:Users:yvankoenig:Desktop:parent:" with properties {name:"Position_01_Raw"}
--> folder "SSD 500:Users:yvankoenig:Desktop:parent:Position_01:Position_01_Raw:"
get name of every file of folder "SSD 500:Users:yvankoenig:Desktop:parent:100EOS5D:" whose visible = true
--> {"DSC_0044.NEF", "DSC_0045.NEF", "DSC_0046.jpg", "DSC_0047.NEF", "DSC_0048.NEF"}
make new folder at end of folder "Position_01" of alias "SSD 500:Users:yvankoenig:Desktop:parent:" with properties {name:"Position_01_Jpg"}
--> folder "SSD 500:Users:yvankoenig:Desktop:parent:Position_01:Position_01_Jpg:"
end tell
tell current application
do shell script "mv '/Users/yvankoenig/Desktop/parent/100EOS5D/DSC_0044.NEF' '/Users/yvankoenig/Desktop/parent/Position_01/Position_01_Raw'"
--> ""
do shell script "mv '/Users/yvankoenig/Desktop/parent/100EOS5D/DSC_0045.NEF' '/Users/yvankoenig/Desktop/parent/Position_01/Position_01_Raw'"
--> ""
do shell script "mv '/Users/yvankoenig/Desktop/parent/100EOS5D/DSC_0046.jpg' '/Users/yvankoenig/Desktop/parent/Position_01/Position_01_Jpg'"
--> ""
do shell script "mv '/Users/yvankoenig/Desktop/parent/100EOS5D/DSC_0047.NEF' '/Users/yvankoenig/Desktop/parent/Position_01/Position_01_Raw'"
--> ""
do shell script "mv '/Users/yvankoenig/Desktop/parent/100EOS5D/DSC_0048.NEF' '/Users/yvankoenig/Desktop/parent/Position_01/Position_01_Raw'"
--> ""
end tell
tell application "System Events"
delete folder "SSD 500:Users:yvankoenig:Desktop:parent:100EOS5D:"
get POSIX path of folder "SSD 500:Users:yvankoenig:Desktop:parent:101EOS5D:"
--> "/Users/yvankoenig/Desktop/parent/101EOS5D"
get name of folder "SSD 500:Users:yvankoenig:Desktop:parent:101EOS5D:"
--> "101EOS5D"
make new folder at end of alias "SSD 500:Users:yvankoenig:Desktop:parent:" with properties {name:"Position_02"}
--> folder "SSD 500:Users:yvankoenig:Desktop:parent:Position_02:"
make new folder at end of folder "Position_02" of alias "SSD 500:Users:yvankoenig:Desktop:parent:" with properties {name:"Position_02_Raw"}
--> folder "SSD 500:Users:yvankoenig:Desktop:parent:Position_02:Position_02_Raw:"
get name of every file of folder "SSD 500:Users:yvankoenig:Desktop:parent:101EOS5D:" whose visible = true
--> {"DSC_0041.NEF", "DSC_0042.NEF", "DSC_0043.NEF", "DSC_0044.NEF", "DSC_0049.jpg"}
make new folder at end of folder "Position_02" of alias "SSD 500:Users:yvankoenig:Desktop:parent:" with properties {name:"Position_02_Jpg"}
--> folder "SSD 500:Users:yvankoenig:Desktop:parent:Position_02:Position_02_Jpg:"
end tell
tell current application
do shell script "mv '/Users/yvankoenig/Desktop/parent/101EOS5D/DSC_0041.NEF' '/Users/yvankoenig/Desktop/parent/Position_02/Position_02_Raw'"
--> ""
do shell script "mv '/Users/yvankoenig/Desktop/parent/101EOS5D/DSC_0042.NEF' '/Users/yvankoenig/Desktop/parent/Position_02/Position_02_Raw'"
--> ""
do shell script "mv '/Users/yvankoenig/Desktop/parent/101EOS5D/DSC_0043.NEF' '/Users/yvankoenig/Desktop/parent/Position_02/Position_02_Raw'"
--> ""
do shell script "mv '/Users/yvankoenig/Desktop/parent/101EOS5D/DSC_0044.NEF' '/Users/yvankoenig/Desktop/parent/Position_02/Position_02_Raw'"
--> ""
do shell script "mv '/Users/yvankoenig/Desktop/parent/101EOS5D/DSC_0049.jpg' '/Users/yvankoenig/Desktop/parent/Position_02/Position_02_Jpg'"
--> ""
end tell
tell application "System Events"
delete folder "SSD 500:Users:yvankoenig:Desktop:parent:101EOS5D:"
get POSIX path of folder "SSD 500:Users:yvankoenig:Desktop:parent:101NCD80:"
--> "/Users/yvankoenig/Desktop/parent/101NCD80"
get name of folder "SSD 500:Users:yvankoenig:Desktop:parent:101NCD80:"
--> "101NCD80"
end tell
Yvan KOENIG running Sierra 10.12.2 in French (VALLAURIS, France) dimanche 18 décembre 2016 20:53:13