简体   繁体   English

什么是测试文件存在的快速方法?

[英]What's a quick way to test to see a file exists?

I want to quickly check to see if a file exists in my iPhone app's Documents directory (or any path for that matter). 我想快速检查我的iPhone应用程序的Documents目录(或任何路径)中是否存在文件。 I can enumerate through the directory's files, or I can try to open a specific file. 我可以枚举目录的文件,或者我可以尝试打开一个特定的文件。 What's the fastest way? 什么是最快的方式? I just need to know if the file is there or if it does not exist. 我只需要知道文件是否存在或者是否存在。

Swift v3: Swift v3:

let fileExists = FileManager.default.fileExists(atPath: somePath)

Thanks to Nikolay Suvandzhiev . 感谢Nikolay Suvandzhiev

Objective-C (Original): Objective-C(原创):

BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:somePath];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在iOS下,有没有一种快速的方法来查看特定UUID的符号? - Under iOS, is there a quick way to see what symbols I have for specific UUID's? $ cordovaFile checkFile()来查看www文件夹中的文件是否存在? - $cordovaFile checkFile() to see if a file that’s in the www folder exists? 测试prepareForSegue是否符合预期的方法 - a way to test if prepareForSegue does what it's supposed to 什么是在Xcode 7的新UI自动化上模拟摇动手势的快速方法? - What's a quick way to simulate the shake gesture on Xcode 7's new UI automation? 有没有办法使用 XCUITest 测试快速操作? - Is there a way to test Quick Actions using XCUITest? 判断NSArray包含哪些对象的快速方法 - Quick way to tell what objects NSArray contains 如何检查是否存在相同的文件 - How to check to see if same exact file exists 在单元测试中对 UIImage 断言的最佳方法是什么? - What's the best way to assert on a UIImage in a unit test? iOS:检测文件编码的最佳方法是什么 - iOS: What's the best way to detect a file's encoding 在Xcode 4中快速切换选项卡的方法是什么? - What is the way to quick-switch between tabs in Xcode 4
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM