automator help with creating new folders, or maybe a script?

Discussion in 'Mac Programming' started by nicolanicola, Mar 5, 2012.

  1. nicolanicola, Mar 5, 2012
    Last edited: Mar 5, 2012

    nicolanicola macrumors member

    Jan 11, 2009
    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.

    Attached Files:

  2. kryten2 macrumors 6502a

    Mar 17, 2012
    Try this little script

    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"
    			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

    Attached Files:

Share This Page