Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Select every nth file from a folder

Hello:


I have a file on my computer that has about 2200 word documents and I need to select every 10th file and place it into another folder. I have zero expierence with this stuff, especially since my imac is my first mac ever; I have had it for about 2 months. Any help would be greatly appreciated !


Thanks

OS X Mavericks (10.9)

Posted on Nov 12, 2013 11:14 AM

Reply
Question marked as Best reply

Posted on Nov 12, 2013 12:09 PM

This script


set sourceFolder to choose folder with prompt "Select Source Folder"

set destinationFolder to choose folder with prompt "Select Destination Folder"


set diag to display dialog "Set skip count" default answer "10"

set skipCount to (text returned of diag) as integer


tell application "Finder"

set theFiles to the files of sourceFolder

repeat with n from skipCount to (count of theFiles) by skipCount


duplicateitemn of theFilestofolder the destinationFolder

end repeat

end tell

will prompt you for the source and destination folders (the destination folder must exist already) and then prompt for the number of files to skip.


It will duplicate the selected files from the source to the destination. If you do not want the files to remain in the source folder replace duplicate with move in the script.


To make the above into a script select all the text in the box then right (control) click the selection, select Services->Make New AppleScript.


As with all script gotten from the web make sure you test it out on some dummy files first and make sure you have backups of the data you are working on.


regards


Note this will start with the file at skipCount and increment from there. That is with the skipCount set to 10 the first file moved is file number 10 then 20, 30, etc.


Message was edited by: Frank Caggiano

7 replies
Question marked as Best reply

Nov 12, 2013 12:09 PM in response to friedmak

This script


set sourceFolder to choose folder with prompt "Select Source Folder"

set destinationFolder to choose folder with prompt "Select Destination Folder"


set diag to display dialog "Set skip count" default answer "10"

set skipCount to (text returned of diag) as integer


tell application "Finder"

set theFiles to the files of sourceFolder

repeat with n from skipCount to (count of theFiles) by skipCount


duplicateitemn of theFilestofolder the destinationFolder

end repeat

end tell

will prompt you for the source and destination folders (the destination folder must exist already) and then prompt for the number of files to skip.


It will duplicate the selected files from the source to the destination. If you do not want the files to remain in the source folder replace duplicate with move in the script.


To make the above into a script select all the text in the box then right (control) click the selection, select Services->Make New AppleScript.


As with all script gotten from the web make sure you test it out on some dummy files first and make sure you have backups of the data you are working on.


regards


Note this will start with the file at skipCount and increment from there. That is with the skipCount set to 10 the first file moved is file number 10 then 20, 30, etc.


Message was edited by: Frank Caggiano

Nov 12, 2013 12:15 PM in response to friedmak

The easiest would probably be to use Automator. I have a Trim Input Items action that can be used to keep every nth item; it can be downloaded here. Using that action, your workflow would be something like:


  1. Ask for Finder Items { Type: Folders } (or another action to get the folder, such as Get Specified Finder Items)
  2. Get Folder Contents
  3. Trim Input Items { Keep Interval 10 items, starting from item 1 }
  4. Move Finder Items { To: wherever } (or Copy Finder Items for testing)


With 2200 documents, I would also recommend testing the workflow, possibly copyiing items instead of moving or looking at the output results to make sure you are selecting the desired files.

May 5, 2014 7:34 AM in response to omerpe

Yes - the Info.plist inside the action bundle contains default parameters that can be edited:


Navigate to the Automator folder in your user's ~/Library folder, and show the package contents (right-click) for the Trim Input Items.action. Open the Info.plist file (inside the Contents folder) in a text editor, and change the entry for maximumItems to the desired number - note that the text field width is set up for 2 digits, so anything larger will get clipped. The entry should look something like:

    <key>maximumItems</key>     <integer>99</integer>


Save the file and restart Automator to have it reload the action.

Select every nth file from a folder

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.