Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
383 views
in Technique[技术] by (71.8m points)

ios - 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). 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Swift v3:

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

Thanks to Nikolay Suvandzhiev.

Objective-C (Original):

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.9k users

...