Skip to content

Instantly share code, notes, and snippets.

@baobao
Created July 3, 2021 01:19
Show Gist options
  • Save baobao/e8caf0f3ba264182f693b29cbf22a214 to your computer and use it in GitHub Desktop.
Save baobao/e8caf0f3ba264182f693b29cbf22a214 to your computer and use it in GitHub Desktop.
- (BOOL) printExistFile:(NSString*) targetFilePath
{
// 【1. ファイルまでのパスを作成】
// ダウンロードした画像が格納されたディレクトリパス取得(適宜変更してください)
NSArray *dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
// ファイルパスの作成
NSString *filePath = [[dirPaths objectAtIndex:0] stringByAppendingPathComponent:targetFilePath];
// 【2. NSFileManagerを取得】
NSFileManager *fileManager = [NSFileManager defaultManager];
// 【3. NSFileManagerのfileExistsAtPathメソッドを実行】
// fileExistsAtPathメソッドでファイルの有無確認
BOOL isExist = [fileManager fileExistsAtPath:filePath];
// 1が出力されたら存在する
NSLog(@"isExist: %d", isExist);
return isExist;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment