# How to unlock a locked file



## yogish (Nov 3, 2008)

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


----------



## Frida (Nov 9, 2008)

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.


----------



## ElDiabloConCaca (Nov 9, 2008)

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.


----------



## Frida (Nov 9, 2008)

ElDiabloConCaca said:


> 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


----------



## Mikuro (Nov 18, 2008)

I'm not sure how to do it in straight C, but you can do it via AppleScript like this:
	
	



```
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:
	
	



```
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:
	
	



```
SetFile -l /path/to/file
```


----------

