PDA

View Full Version : automator help with creating new folders, or maybe a script?




nicolanicola
Mar 5, 2012, 10:36 AM
I have a folder structure as follows all items>item name>item colour>files.

Now in this item colour folder are 2 files, a large sized image and a thumbnail version of that image. I need to create a folder in here called thumbnail and move the thumbnail image into it. Can I do this with automator?

I have maybe about 30 item name folders with various amounts of folders within each of those.

If I was to say what it was in code terms it'd be for every folder in all items,open folder then go in every folder in here and create a directory called thumbnail and move the file named closeupTN.jpg into here.

I've attached a folder structure. It starts from the contents of 'all items' in the above description.



kryten2
Apr 17, 2012, 08:26 PM
I assume all items is a folder? Choose this toplevel folder in the choose folder dialog when you run the script.

set the_folder to (choose folder with prompt "Choose your “all items“ folder")
set FilenamesList to paragraphs of (do shell script "find " & quoted form of POSIX path of the_folder & " -type f -name *TN.jpg")
repeat with i from 1 to count of FilenamesList
set thisFileObject to (POSIX file (item i of FilenamesList) as alias)
-- do something with the file object "thisFileObject"
tell application "Finder"
try
set tumbnailFolder to make new folder in container of thisFileObject with properties {name:"thumbnail"}
move thisFileObject to tumbnailFolder
on error errMsg number errNumber
display alert errMsg message errNumber
end try
end tell
end repeat