Can't delete file

Here is a snippet from a script that I’m writing:

set tmpFilePathName to "/tmp"
set localPrefsPath to POSIX file tmpFilePathName
set prefFile to ".GFTPprefs"
set localPrefs to POSIX file (tmpFilePathName & "/" & prefFile)

tell application "Finder"
	set PREFS to read file localPrefs
	display dialog PREFS
	delete file localPrefs
end tell

I know the “sets” at the beginning are a little convoluted - there is other stuff that’s using them.

When this is run, I get an error on “delete file localPrefs”

On the other hand, the “set PREFS to read file localPrefs” works just fine. I’ve checked and the file is still there.

Any guesses?

T.

You don’t have permission to delete a file in /tmp. Use “Go” in the Finder to go to /tmp and get info for the file to see what its permissions are. To delete it, you’ll have to use a shell script.

Permissions are read write for me on this file. Actually this script creates the file and a different one; both are in the tmp folder. The other file deletes fine.

T.

Then use do shell script “rm …”; see the man page for rm. Be careful, a removed file is NOT recoverable and you want to be very certain you are not removing the directory.

Hi Tim,

localPrefs is a file specifier (file URL),
so the repetition of the keyword file causes the error.
My suggestion

set tmpFilePathName to "/tmp"
set localPrefsPath to POSIX file tmpFilePathName
set prefFile to ".GFTPprefs"
set localPrefs to POSIX file (tmpFilePathName & "/" & prefFile) as alias

set PREFS to read localPrefs

tell application "Finder"
	display dialog PREFS
	delete localPrefs
end tell

OK, this is just weird. I found the solution but it doesn’t make sense (this was posted before Sefan’s response above).

I have two file which the script puts in /tmp. They are defined as:

	set tmpFilePathName to "/tmp"
	set manifestFileSuffix to " Manifest.txt"
	set useLockFile to true
	set lockFile to ".UploadLock"
	set prefFile to ".GFTPprefs"
	set localPrefsPath to POSIX file tmpFilePathName
	set localPrefs to POSIX file (tmpFilePathName & "/" & prefFile)

-- Later in script
	set tmpFilePathName to tmpFilePathName & "/" & putDirName & manifestFileSuffix
	set manifestTextFile to POSIX file tmpFilePathName

This is a summary of the commands. They are actually defined in a couple of different routines, I’m not if that makes a difference or not. I see now that “tmpFilePathName” gets redefined, but I wouldn’t think this would affect the localPrefs definition.

Anyway, the following delete commands work for both files:

tell application "Finder"
delete file manifestTextFile
delete localPrefs
end tell

However, if I use “delete file localPrefs” in the finder block, it fails with the error in the first post. I’m just not seeing the difference between the two files. Why does one need “file” and the other hates it?

Thanks,

T.

I recommend to avoid «class furl» (file URL), which is the result of the command POSIX file.
file URL behaves differently under certain circumstances
Better use class alias or a Finder file specifier

Thanks for the info!

T.