0

At runtime, my app downloads some large video files and plays them. They are large, so I figure they might get wiped at any time by the system trying to recover memory.

I had trouble using [fileManager fileExistsAtPath: pathOfVideo]:

Then I found an answer saying we should not use -fileExistsAtPath to determine if files exist.

The suggested solution is to open the file and see if it fails on opening. Even for 30MB files? I'm not so worried about race conditions here; the files are downloaded from the server and played in MediaPlayer. Should I still open the 30MB file to see if it exists instead of using fileExistsAtPath?

Community
  • 1
  • 1
Thunder Rabbit
  • 5,405
  • 8
  • 44
  • 82
  • (for the record, my problem was with directory permissions, but the question about large file detection remains answerable..) – Thunder Rabbit May 24 '12 at 11:04

3 Answers3

1

May be this will help you

NSDictionary *fileAttributes = [fileManager fileAttributesAtPath:filePath traverseLink:YES];
    if(fileAttributes != nil)
    {
        NSString *fileSize = [fileAttributes objectForKey:NSFileSize];
    enter code here

        NSLog(@"File size: %@ kb", fileSize);
    }
Amitg2k12
  • 3,765
  • 10
  • 48
  • 97
  • could be nice, but xcode says 'fileAttributesAtPath:traverseLink:' is deprecated – Thunder Rabbit May 24 '12 at 11:16
  • check this http://developer.apple.com/library/ios/#DOCUMENTATION/Cocoa/Reference/Foundation/Classes/NSFileManager_Class/Reference/Reference.html#//apple_ref/occ/instm/NSFileManager/attributesOfItemAtPath:error: – Amitg2k12 May 24 '12 at 11:56
  • 1
    Try `attributesOfItemAtPath:error:`, as suggested by the documentation. – Rob May 24 '12 at 12:26
1

If race conditions aren't a concern use fileExistsAtPath. What was the permissions issue on iOS device?

ader
  • 5,403
  • 1
  • 21
  • 26
  • ~/Library/Application Support/iPhone Simulator/5.0 was 700 so I changed it to 755 to match the rest of its parents and children. – Thunder Rabbit May 24 '12 at 21:25
0

If you follow the links to the discussion of why one is advised not to use fileExistsAtPath (see Race Conditions and Secure File Operations), given the sandboxing of iPhone apps, it might be an acceptable risk.

Rob
  • 415,655
  • 72
  • 787
  • 1,044