I have an excel file with a list of codes (64579, 56887, etc.);
I want to find every file on my server which name contains these codes (no matter the extension - eg. 64579.tif, 64579.jpg, etc.);
I want to make a copy of all the found files into a separate folder on my desktop
I found a script which is quite similar to my purpose (bbs.macscripter.net/viewtopic.php?id=25729), but I want to do the search on my entire server, no matter how many folders/subfolders are there in it and no matter how many different types of extensions.
If your volume is indexed the best way would be "mdfind "
Would be something like the code below:
set TheSearchPath to quoted form of POSIX path of (choose folder with prompt "Choose the Searchfolder")
set TheDestPath to quoted form of POSIX path of (choose folder with prompt "Choose the DestFolder")
set theSearch to "yourSearchstring" --place your sample-searchstring here to test the search
set theResult to paragraphs of (do shell script "mdfind -onlyin " & TheSearchPath & " 'kMDItemFSName == \"*" & theSearch & "*\"'")
repeat with i from 1 to count of theResult
if (count of theResult) is 1 and item 1 of theResult is "" then exit repeat --no matches
set the PosixFile to item i of theResult
try
do shell script "cp -f " & quoted form of PosixFile & space & TheDestPath
end try
end repeat
I have hundreds, sometimes thousands of files to pull from a server. They list in excel, single column, and usually have 5 to 6 characters. Is there a way to use the excel or txt file and pull the files (jpg, tif, eps, etc) from the server and copy to destination folder? I couldn’t get your script to ask for the csv or excel. Thanks again for your time.
the first script was for you to test the mdfind-command …
this one should read the CSV, search the Volume and copy files to folder … if the volume is indexed …
set CSVList to (paragraphs of (read (choose file with prompt "Choose the CSV-File"))) --read csv-file
set TheSearchPath to quoted form of POSIX path of (choose folder with prompt "Choose the Searchfolder") --set Searchpath
set TheDestPath to quoted form of POSIX path of (choose folder with prompt "Choose the DestFolder") --set DestFolder
repeat with j from 1 to count of CSVList
set theSearch to item j of CSVList
set theResult to paragraphs of (do shell script "mdfind -onlyin " & TheSearchPath & " 'kMDItemFSName == \"*" & theSearch & "*\"'")
repeat with i from 1 to count of theResult
if (count of theResult) is 1 and item 1 of theResult is "" then exit repeat --no matches
set the PosixFile to item i of theResult
try
do shell script "cp -f " & quoted form of PosixFile & space & TheDestPath
end try
end repeat
end repeat