On Mar 19, 2010, at 4:59 AM, Nikhil Khandelwal wrote:

> Is there any way to lock a file in cocoa? I want to lock a file on desktop 
> programmatically so that I can't move that file to trash until I unlock the 
> file.

I recommend against doing that.  Locking the file in this sense should probably 
be left in the user's domain.

That said, the lock that corresponds to the "Locked" checkbox in the Get Info 
window is represented in the APIs in a couple of different ways:

With NSFileManager, you can set the NSFileImmutable attribute for a file.  See 
-setAttributes:ofItemAtPath:error: and -createFileAtPath:contents:attributes:.

In the chflags(2) system call, it is the UF_IMMUTABLE flag.

In the File Manager APIs, it's the kFSNodeLocked{Bit|Mask} in the nodeFlags of 
a FSCatalogInfo structure.

Cheers,
Ken

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to