How to check whether a file is locked in Cocoa?

后端 未结 3 1510
南方客
南方客 2021-02-06 15:47

Is there any API to check whether a file is a locked? I am not able to find any API in the NSFileManager class.Let me know if there is any API to check the lock of

3条回答
  •  无人及你
    2021-02-06 16:25

    Following Code worked for me.

    NSError * error;
    NSDictionary *attributes = [[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:&error];
    BOOL isLocked = [[attributes objectForKey:NSFileImmutable] boolValue];
                
    if (isLocked) {
        NSLog(@"File is locked");
    }
    

提交回复
热议问题