Benches macOS

3

Script to move files from a list

apple Verified

Imported from the Apple Support Forums via the Wayback Machine 🔗

I have 27 000 images in a folder.

I need to separate 6000 of them into a new folder.

I have a list of all the file names I need to separate.

Is there anyway some kind of script can do this?

So for example:

12003.jpg

14300.jpg

14401.jpg

I have a list like this. And the files are named like that. Can a script run through my list and move those files to a new folder?

3 replies

Sign in or join Beachball Help to reply.

  1. 0

    VikingOSX

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Here is a AppleScript that has three prompts:

    1. Your text file containing a list of the images to move
    2. The folder containing 27 000 images
    3. The folder where 6000 are moved too.

    Assumptions:

    1. The list is one image name per line.
    2. Those 27 000 images are not in sub-directories though that can be managed with an additional word in the script.
    3. No duplicates handling in the script

    Flow:

    1. Prompt for the list of images to move
    2. Prompt for the folder containing the 27 000 images
    3. Prompt for the destination folder of the 6000 images
    4. Read list of images into a list
    5. Get list of files in among the 27 000 that match the list of names
    6. Move each file to the destination folder

    It is AppleScript so it won't be quick, but it is methodical. Copy and paste the following into Script Editor (Dock : Launchpad : Other : Script Editor). Click the compile button, and then click run.

    -- matchmove.applescript
    -- read in list of images from a text file, and then select only those matching
    -- images in the inFolder. Move each matching file from the inFolder to the outFolder.
    -- Reference: https://discussions.apple.com/thread/250161568
    -- VikingOSX, 2019-02-13, Apple Support Community
    
    property istext : {"public.text", "public.plain-text"}
    property adesktop : (path to desktop) as alias
    
    set moveList to {}
    set matchList to {}
    
    set myList to (choose file with prompt "Select file containing list:" of type istext default location adesktop without invisibles, multiple selections allowed and showing package contents)
    
    set inFolder to (choose folder with prompt "Select Image move-from folder: " default location adesktop without invisibles, multiple selections allowed and showing package contents)
    
    set outFolder to (choose folder with prompt "Select Image move-to folder: " default location adesktop without invisibles, multiple selections allowed and showing package contents)
    
    # read the text file contents into a list of the images to move
    set moveList to read myList as «class utf8» using delimiter linefeed
    
    tell application "Finder"
    	set matchList to (every file in folder inFolder whose name is in moveList) as alias list
    	
    	repeat with anItem in matchList
    		move anItem to folder outFolder
    	end repeat
    end tell
    return
    

  2. 0

    John-Eagleton

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    Just wow! It worked perfectly. Thank you so much, you really made my day.

  3. 0

    VikingOSX

    Imported from the Apple Support Forums via the Wayback Machine 🔗

    You are welcome.