4

Right now I am working on an iOS app that needs NSFileManager but when I do the attributesOfItemAtPath: method, it returns null. This also fails on NSData and the dataWithContentsOfFile: method. I do not understand why this is happening. The file URL that I am using looks something like this :file://localhost/private/var/mobile/Applications/597DE145-33D7-4F92-AE95-029D5CF15291/tmp/Kv7DWqtRWH7WnN47HdDW.I suspect it might be something to do with the URL, but I am not sure.

tshepang
  • 12,111
  • 21
  • 91
  • 136
virindh
  • 3,775
  • 3
  • 24
  • 49

1 Answers1

13

You need to convert the NSURL to a path for use with any of the NSFileManager methods that take a string. Do this by calling the path method on the URL.

NSURL *someURL = ... // some file URL
NSString *path = [someURL path]; // convert the file:// URL to a file path
NSDictionary *info = [[NSFileManager defaultManager] attributesOfItemAtPath:path];
rmaddy
  • 314,917
  • 42
  • 532
  • 579