Making a dropplet to combine text files from one folder

I have searched the posts here for a solution, but apparently my noobie-ness is limiting my success. I did find one wonderful script …


choose folder with prompt "Combine all text files from this folder:"
set sourceFolder to result

choose file name with prompt "Save combined text file as:" default location result default name "untitled.txt"
set combinedFile to quoted form of POSIX path of result
-- display dialog "the value of sourcefolder is" & sourceFolder
-- display dialog "the value of combinedfile is" & combinedFile
try
	do shell script "cd " & quoted form of POSIX path of sourceFolder & "; cat *.txt > " & combinedFile
on error errorMsg number errorNum
	display dialog "Error: (" & errorNum & "):" & return & return & errorMsg buttons "Cancel" default button 1
end try

but alas, I really need this in a droplet so my feeble attempt to convert went something like this…


on open (theItems)
	tell application "Finder"
		set sourceFolder to quoted form of POSIX path of (container of first item of theItems as string)
		set combinedFile to quoted form of POSIX path of (container of first item of theItems as alias) & "00-Data.txt"
		display dialog "the value of sourcefolder is" & sourceFolder
		display dialog "the value of combinedfile is" & combinedFile
		do shell script "cd " & quoted form of POSIX path of sourceFolder & "; cat *.txt > " & combinedFile
	end tell
end open

the display dialogs were added in an attempt to debug, but i have not the skill set to do this.

All the files will always be saved as “00-Data.txt” I can tell that adding the filename the way I am is causing the problem, because the display dialog from the working script displays the path with the filename outside the quotes. Any help would be great.

thanks all,
Shawn

Hi,

use a pair of parentheses to include the whole path in the quotation.
In your script you have twice quoted form of POSIX path of [sourceFolder] this cannot work
I cleaned up this part a bit


on open (theItems)
	tell application "Finder"
		set sourceFolder to POSIX path of (container of first item of theItems as alias)
		set combinedFile to quoted form of (sourceFolder & "00-Data.txt")
		display dialog "the value of sourcefolder is" & sourceFolder
		display dialog "the value of combinedfile is" & combinedFile
		do shell script "cd " & quoted form of sourceFolder & "; cat *.txt > " & combinedFile
	end tell
end open

Thanks so much StefanK, worked like a charm. Exactly as needed. Thanks again…