Banging my head on the wall: why can't I get Every File Of???

Grrr…this should be so simple. I googled and searched everywhere, and I seem to have it coded just fine, but it won’t work!!

directory: ~/Desktop/gcal
contents: .xml files

script:

tell application "Finder" to set myFolder to "Xamego:Users:mlafleur:Desktop:gcal" as string

set theFiles to every file of myFolder whose name extension is "xml"

Error: Can’t get every file of “Xamego:Users:mlafleur:Desktop:gcal”

I tried using slashes in the path, I tried using “as alias” and as nothing, I tried parenthesis. I don’t understand what the problem is. Why the hell is this so cryptic?

Hi,

two mistakes:
You try to get files of a string, not a folder, and you should target the Finder to do this


set myFolder to ((path to desktop as text) & "gcal")
tell application "Finder" to set theFiles to every file of folder myFolder whose name extension is "xml"

Two things going on here.

First ‘files of’ and its various forms of functions of the Finder so it must be enclosed inside a tell block.

Second ‘of myfolder’ doesn’t work because myfolder is a string. So instead you need to specify that its a folder.

tell application "Finder"
	set myFolder to "Xamego:Users:mlafleur:Desktop:gcal" as string
	set theFiles to every file of folder myFolder whose name extension is "xml"
end tell

Ya got me this time Stefan :stuck_out_tongue:

Brazuca: or you could have declared myfolder as an alias rather than string and then the ‘folder’ designation wouldn’t have been needed.

tell application "Finder"
	set myFolder to "Xamego:Users:mlafleur:Desktop:gcal" as alias
	set theFiles to every file of myFolder whose name extension is "xml"
end tell

Thanks guys. I’m such a noob. I had tried the alias thing, but outside the Finder’s tell block. Silly me.

Now, on to find a way to convert all these xml files to csv or a format that Google Calendar understands (XSLT Tools doesn’t seem to work in Leopard, so I have to read about creating structured documents)…Maybe it is easier to convince the source to make an RSS feed after all…

edit: Actually, this solved a problem but showed me another. I’m guessing this has to do with POSIX paths.

set myFolder to ((path to desktop as text) & "gcal")
tell application "Finder" to set theFiles to every file of folder myFolder whose name extension is "xml"
repeat with i from 1 to the count of theFiles
	
	set theOld to item i of theFiles
	set thisPath to (path of theOld)
	set theCommand to "sed -i -e 's/\"/\\\"/g' " & thisPath
	
	#sed -i -e 's/\"/\\\"/g' /Users/mlafleur/Desktop/gcal/P31733.xml  <<this is the actual command that works in terminal. I need "/" in the path, not ":"
	
	do shell script theCommand

	#parse XML alias (myFolder & theOld)
end repeat

Gets an error “Can’t get path of document file P31625.xml…”. The variable “thisPath” has to not include the HDD name and use “/”. Is this for POSIX?