如何检查可可中的文件是否被锁定? [英] How to check whether a file is locked in Cocoa?
本文介绍了如何检查可可中的文件是否被锁定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有用于检查文件是否被锁定的API?我无法在NSFileManager
类中找到任何API.请告知是否有任何API可以检查文件的锁定.
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 the file.
我找到了以下与文件锁定有关的链接
I found the following link related to file lock
http://lists.apple.com/archives/cocoa-dev/2006/Nov/msg01399.html
我可以在文件上调用– isWritableFileAtPath:.还有其他方法可以查看文件是否被锁定吗?
I can invoke – isWritableFileAtPath: on file. Is there any other way to find whether a file is locked?
推荐答案
以下代码对我有用.
NSError * error;
NSDictionary *attributes = [[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:&error];
BOOL isLocked = [[attributes objectForKey:@"NSFileImmutable"] boolValue];
if(isLocked)
{
NSLog(@"File is locked");
}
这篇关于如何检查可可中的文件是否被锁定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文