POSIX file not existing.

Hi,

I have made a checker to see if a file exists based on defined path and file from variables.

I have tried POSIX path and POSIX file but it still says the file does not exist…

can anybody help?

Thanks,
Bruce

Hi,

I guess you have to tell the Finder or System Events to perform the check

Hello.

It would be interesting to see your code.

here is the code for it

set parentFolder to getParentFolder(path to me)

set ProductCode to "EF-LG-P"

set labelFile to "nomesh.laba"

if ProductCode contains "EF" then
	set path1 to "EF"
else if ProductCode contains "JF" then
	set path1 to "JF"
else if ProductCode contains "CF" then
	set path1 to "CF"
else if ProductCode contains "UF" then
	set path1 to "UF"
end if
if ProductCode contains "LG" then
	set path2 to "LG"
else if ProductCode contains "MD" then
	set path2 to "MD"
else if ProductCode contains "ST" then
	set path2 to "ST"
else if ProductCode contains "SM" then
	set path2 to "SM"
end if
if ProductCode contains "P" then
	set path3 to "P"
else if ProductCode contains "E" then
	set path3 to "E"
end if

set labelPath to path2 & ":" & path1 & ":" & path3 & ":"

set filePath to parentFolder & "labels" & ":" & labelPath & ":" & labelFile
tell application "Finder"
	if exists file filePath then
		open file filePath as string
	else
		display dialog "The file '" & filePath & "' does not exist"
	end if
end tell

-------------------------------------
on getParentFolder(_alias)
	local parentFolder
	set {oldTIDS, AppleScript's text item delimiters} to {AppleScript's text item delimiters, ":"}
	set _alias to _alias as text
	if _alias ends with ".app:" then
		set parentFolder to ((text items 1 thru -3 of _alias) as text) & ":"
	else
		set parentFolder to ((text items 1 thru -2 of _alias) as text) & ":"
	end if
	set AppleScript's text item delimiters to oldTIDS
	return parentFolder
end getParentFolder

What’s wrong with


tell application "System Events" to set parentFolder to path of container of (path to me)

?

I had someone work with me on it and I have been updating it and that is how they set the parent folder, I think that is because they compiled it into an app and the resources are all stored outside of the app but with in the containing folder

container in System Events refers always to the parent folder regardless of the kind of the calling object

Maybe not in this situation but it has some limitations:

  • It’s slower than than using text item delimiters
  • The file needs to exists in order to work.
  • It requires a running instance of System Events, which could be blocked by another process.

Ah now I understand why it was put in but now that I put that in instead of the handler it seems to work so I am not sure as to why it is doing it…

Thanks,
Bruce