I want to select a folder of QuickTime movies and copy each one into separate sub folders depending on the filename (by copying not moving).

I have a folder that I want to contain sub folders called XA and XB, but I only want them to copy across the h264 versions.

Example file names are as follows:


What would be an efficient way of coding this?

  • 1
    I'd just do it from Terminal by changing directory to XA and using the following compound command, where ../XB/ is the path to the XB folder: for f in *_h264.mov; do cp "$f" ../XB/; done – user3439894 Jul 22 '18 at 20:48

Apologies in advance if you only wanted a script. I would have commented, but I'm 5 rep short. This isn't an applescript/automator, but it still might help.

You can use Find any file. Website description:

Find Any File is a program for Apple's Mac OS X that lets you search for files on your disks.

  • Contrary to Spotlight, it does not use a database but instead uses the file system driver's fast search operations, where available. This lets you search for file properties such as name, dates, size, etc., but not for file content (that's what Spotlight is best at!) — unless you want to find plain text only).
  • Find Any File can find files that Spotlight doesn't, e.g. those inside bundles and packages and in inside folders that are usually excluded from Spotlight search.
  • Finally, it is quite fast. A search only takes a few seconds on an internal hard disk or SSD. Try for yourself!

Basically, it's like "Everything" for mac. But what you could do is search for any file that ends with "_h264.mov" within the folder (whatever folder you feel like. If you want to automate, I suppose you could do a GUI script of find any file, but you might find another solution.

Example image: enter image description here

  • +1 Good Solid answer. Oh and Welcome to AskDifferent :) – JBis Jul 28 '18 at 5:02

This is an AppleScript you can use. You can save it as an application, then drop the folder containing your file, or run the script and select that folder when prompted. It copies the files with "h264" in their names to Sub Folder XA, and moves the files without "h264" in their names to Sub Folder XB. The original files that have "h264" in their names aren't moved, so you will have two of each, one in the original folder and one in the Sub Folder XA folder.

property done_foldername : "Sub Folder XA"
property originals_foldername : "Sub Folder XB"
property extension_list : {"mov"}

on open these_items
    my build_distribution(these_items's item 1)
end open

on build_distribution(this_item)
    set this_folder to this_item as string
    set done_FolderPath to this_folder & done_foldername
    set originals_FolderPath to this_folder & originals_foldername
    tell application "Finder"
        if not (exists folder done_FolderPath) then
            make new folder at this_folder with properties {name:done_foldername}
        end if
        if not (exists folder originals_FolderPath) then
            make new folder at this_folder with properties {name:originals_foldername}
            set current view of container window of folder this_folder to list view
        end if
        set the originals_folder to originals_FolderPath as alias
        set these_items to (every file of entire contents of folder this_folder as list)
    end tell
        repeat with i from 1 to number of items in these_items
            set this_item to (item i of these_items) as alias
            set the item_info to the info for this_item
            if (alias of the item_info is false and the name extension of the item_info is in the extension_list) then
                if the displayed name of item_info contains "h264" then
                    set copy_Me to "1"
                    set copy_Me to "0"
                end if
                    tell application "Finder"
                        if copy_Me = "1" then
                            duplicate this_item to folder done_FolderPath
                            move this_item to folder originals_folder with replacing
                        end if
                    end tell
                on error the error_message number the error_number
                    display dialog "Error: " & the error_number & ". " & the error_message buttons {"OK"} default button 1
                end try

            end if
        end repeat
    on error error_message number error_number
        if the error_number is not -128 then
            tell application "Finder"
                display dialog error_message buttons {"Cancel"} default button 1 giving up after 120
            end tell
        end if
    end try
end build_distribution

on run
    set this_item to (choose folder)
    my build_distribution(this_item)
end run

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .