How to unlock a locked file

yogish

Registered
Hi,

I am trying to delete a files using remove(). But, the locked file fails in remove() .
I am looking for the api/function to unlock a locked file.
Does anyone knows how to unlock a locked file .

Thanks
 
If you click once on the file and go to the File menu and select 'Get Info', under the 'General' setting in the info window there is a little tick box which says 'Locked'. Make sure it is not ticked, then delete the file by moving it to the trash and emptying it. You could also delete is by holding down the Alt/Option key when emptying the trash.
 
I think since this is posted in "Software Programming & Web Scripting" that the original poster is looking for a way to unlock a file via some programming API (as stated in the original post) -- not by directly manipulating the file with the Finder.
 
I think since this is posted in "Software Programming & Web Scripting" that the original poster is looking for a way to unlock a file via some programming API (as stated in the original post) -- not by directly manipulating the file with the Finder.

Well, then it's above my head :(
 
I'm not sure how to do it in straight C, but you can do it via AppleScript like this:
Code:
tell application "Finder"
	set the locked of file "Mac HD:path:to:file" to false
end tell
Or if you want to use Unix-style paths instead of HFS-style paths, like this:
Code:
tell application "Finder"
	set the locked of file (posix file "/path/to/file") to false
end tell

You can also use the SetFile Terminal command:
Code:
SetFile -l /path/to/file
 
Back
Top