Find files on server from csv list - copy to single folder

Hello,

I have this situation:

  • 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.

Any input would be greatly appreciated !! Thanks.

I too am looking to do something like this. Anyluck?

Hi,

the csv-file could be read in a list by AS …

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.

Hi,

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

Will this work against a Windows Server? Thanks again Hans-Gerd Classen for all your help.