Trying to compile list of files

Hi, I am trying to write a script which will search a server in multiple folder locations for files which have certain extensions and characters. (Ie. I need to search for a file named: R FPTR 9488-1.pdf or similar.) Then having compiled this list to display and give me the option to paste it into a word file (the script must create this new word file).

I have searched and searched online including in this forum. I am new to scripting and want to learn. I have written the script below and using event logger in script editor I get this output:


tell current application
	choose folder with multiple selections allowed without invisibles
		{alias "Macintosh HD:Users:corin:Documents:JJL:PDF's and logos JJL:"}
	path to desktop as alias
		alias "Macintosh HD:Users:corin:Desktop:"
end tell
tell application "Finder"
	get every file of entire contents of alias "Macintosh HD:Users:corin:Desktop:" whose name extension contains "pdf -doc" and name starts with "FPTR -TR -FR"
		{}
		"Can't make \"\" into type alias."

Any ideas?


try
	set report_folder to choose folder with multiple selections allowed without invisibles
	set the report_folder to path to desktop folder as alias
end try

tell application "Finder"
	{files of entire contents of report_folder whose name extension contains "pdf -doc" and name starts with "FPTR -TR -FR"}
end tell
set search_result to result as string
set file_list to result as alias

tell application "/Applications/Microsoft Office 2004/Microsoft Word"
	activate
	open file_list
end tell

Model: Mac Book Pro Intel G4
AppleScript: 2.2.1 (100.1)
Browser: Firefox 3.0.4
Operating System: Mac OS X (10.5)

Hi bearpiper,

I do not know, if my code also works with server volumes, but it works here on my Mac running Mac OS X 10.5 & MS Word 2004. Please note, that you will need to adjust the searchstring to your requirements:


on run
	set chosenfolders to (choose folder with prompt "please choose folders:" with multiple selections allowed without invisibles)
	set searchstring to "*.pdf"
	set foundfiles to ""
	repeat with chosenfolder in chosenfolders
		try
			set filepaths to (do shell script "find " & quoted form of POSIX path of chosenfolder & " -name " & quoted form of searchstring)
			set foundfiles to foundfiles & (filepaths & return)
		end try
	end repeat
	if foundfiles is not "" then
		tell application "Microsoft Word"
			activate
			make new document
			tell document 1
				set textrange to create range start 0 end 0
				insert text foundfiles at textrange
			end tell
		end tell
	end if
end run

Martin,

Once I changed the search string to look for what I wanted, and added script for mounting the server, your script worked fine.

Thanks very much you have saved me hours of time!!:slight_smile:

Thanks,
Corin


A Pessimist is just an optimist with more experience!