Forums
New posts
Articles
Product Reviews
Policies
FAQ
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Menu
Log in
Register
Install the app
Install
Forums
macOS & iOS Developer Playground
macOS - Development and Darwin
Need help with AppleScript for searching CSV file for matches to copy
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="absuk" data-source="post: 1722005" data-attributes="member: 379687"><p>Hi,</p><p></p><p>I am totally useless scripting, so i hope you can help. I got this script from macscripter.com and i can not get the **** thing to work, seems to only pick up the first filename in the CSV and leave the rest, what is missing?</p><p></p><p>I have 300 files to match and this will save me a whole bunch of a head ache. please help.</p><p></p><p>I am using EL Captain, maybe there is something that has in AppleScript in this version?</p><p></p><p></p><p>[CODE]</p><p>--Sur la Table script for copying files to a new location using a CSV file as source.</p><p>--This script assumes the following:</p><p>-- The CSV file contains no empty cells and no erroneous filenames</p><p>-- The files indicated in the CSV file are actually located in the SOURCE folder</p><p></p><p></p><p>tell application "Finder"</p><p> activate</p><p> </p><p> --CODE for getting the INFO from a file</p><p> set CSV_source_File to choose file with prompt "Select the CSV file containing the filenames you need to find and duplicate." without invisibles</p><p> set OldDelims to AppleScript's text item delimiters</p><p> set AppleScript's text item delimiters to {return} --this MUST be return when using CSV files</p><p> </p><p> --CODE telling the script to make a list from the selected file.</p><p> set Source_List to every text item of (read CSV_source_File as string)</p><p> set AppleScript's text item delimiters to OldDelims</p><p> </p><p> --CODE for choosing your SOURCE:</p><p> set Source_Folder to choose folder with prompt "Choose SOURCE FOLDER of files." & return & "(Files here that match the filenames in your CSV file" & return & "will be duplicated to a new TARGET location.)" without invisibles</p><p> --display dialog "You have chosen SOURCE FOLDER:" & return & Source_Folder -- this is just feedback and can be deleted</p><p> set Source_Folder_full_list to files of entire contents of Source_Folder</p><p> </p><p> --CODE for choosing your TARGET: </p><p> set Target_Folder to choose folder with prompt "Choose a TARGET FOLDER to duplicate the SOURCE files to." & return & return & "The count of files to be duplicated is " & return & (count of Source_List) & return & "Please check the folder when done." without invisibles</p><p> --display dialog "You have chosen TARGET FOLDER:" & return & Target_Folder -- this is just feedback and can be deleted</p><p> </p><p> </p><p> </p><p> --Here's the meat of it:</p><p> repeat with i from 1 to (count Source_Folder_full_list)</p><p> set file_source_One to item i of Source_Folder_full_list</p><p> set file_source_OneName to name of file_source_One</p><p> </p><p> if (file_source_OneName is in Source_List) then</p><p> duplicate file_source_One to Target_Folder with replacing</p><p> end if</p><p> </p><p> end repeat</p><p> beep 1</p><p> display dialog "All files were duplicated as requested." giving up after 3</p><p> </p><p>end tell[/CODE]</p><p></p><p></p><p></p><p>so if a CSV has the below</p><p></p><p>fileX2.png</p><p>fileY2.png</p><p></p><p></p><p>the script seems to only pick the first CSV value fileX2.png even though the other fileY2.png is in the folder.</p></blockquote><p></p>
[QUOTE="absuk, post: 1722005, member: 379687"] Hi, I am totally useless scripting, so i hope you can help. I got this script from macscripter.com and i can not get the **** thing to work, seems to only pick up the first filename in the CSV and leave the rest, what is missing? I have 300 files to match and this will save me a whole bunch of a head ache. please help. I am using EL Captain, maybe there is something that has in AppleScript in this version? [CODE] --Sur la Table script for copying files to a new location using a CSV file as source. --This script assumes the following: -- The CSV file contains no empty cells and no erroneous filenames -- The files indicated in the CSV file are actually located in the SOURCE folder tell application "Finder" activate --CODE for getting the INFO from a file set CSV_source_File to choose file with prompt "Select the CSV file containing the filenames you need to find and duplicate." without invisibles set OldDelims to AppleScript's text item delimiters set AppleScript's text item delimiters to {return} --this MUST be return when using CSV files --CODE telling the script to make a list from the selected file. set Source_List to every text item of (read CSV_source_File as string) set AppleScript's text item delimiters to OldDelims --CODE for choosing your SOURCE: set Source_Folder to choose folder with prompt "Choose SOURCE FOLDER of files." & return & "(Files here that match the filenames in your CSV file" & return & "will be duplicated to a new TARGET location.)" without invisibles --display dialog "You have chosen SOURCE FOLDER:" & return & Source_Folder -- this is just feedback and can be deleted set Source_Folder_full_list to files of entire contents of Source_Folder --CODE for choosing your TARGET: set Target_Folder to choose folder with prompt "Choose a TARGET FOLDER to duplicate the SOURCE files to." & return & return & "The count of files to be duplicated is " & return & (count of Source_List) & return & "Please check the folder when done." without invisibles --display dialog "You have chosen TARGET FOLDER:" & return & Target_Folder -- this is just feedback and can be deleted --Here's the meat of it: repeat with i from 1 to (count Source_Folder_full_list) set file_source_One to item i of Source_Folder_full_list set file_source_OneName to name of file_source_One if (file_source_OneName is in Source_List) then duplicate file_source_One to Target_Folder with replacing end if end repeat beep 1 display dialog "All files were duplicated as requested." giving up after 3 end tell[/CODE] so if a CSV has the below fileX2.png fileY2.png the script seems to only pick the first CSV value fileX2.png even though the other fileY2.png is in the folder. [/QUOTE]
Verification
Name this item. 🍎
Post reply
Forums
macOS & iOS Developer Playground
macOS - Development and Darwin
Need help with AppleScript for searching CSV file for matches to copy
Top