gpt4 book ai didi

ios - NSFileManager,如何判断一个文件或目录是否可以删除?

转载 作者:行者123 更新时间:2023-11-28 22:02:50 35 4
gpt4 key购买 nike

有没有办法告诉,如果调用

[[NSFileManager defaultManager] removeItemAtPath:filePath error:NULL];

会失败吗?

最佳答案

我想你想看看 NSFileManager 的 -isDeletableFileAtPath: 它对文件和目录都有效 https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSFileManager_Class/Reference/Reference.html#//apple_ref/occ/instm/NSFileManager/isDeletableFileAtPath :

但是,您可能应该注意文档中列出的注意事项:

Note: Attempting to predicate behavior based on the current state of the file system or a particular file on the file system is not recommended. Doing so can cause odd behavior or race conditions. It's far better to attempt an operation (such as loading a file or creating a directory), check for errors, and handle those errors gracefully than it is to try to figure out ahead of time whether the operation will succeed. For more information on file system race conditions, see “Race Conditions and Secure File Operations” in Secure Coding Guide.

尝试删除它并检查错误而不是传递 NULL

关于ios - NSFileManager,如何判断一个文件或目录是否可以删除?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24704421/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com