Finding file’s size

Try this; NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:URL error:&attributesError]; NSNumber *fileSizeNumber = [fileAttributes objectForKey:NSFileSize]; long long fileSize = [fileSizeNumber longLongValue]; Note that the fileSize won’t necessarily fit in an integer (especially a signed one) although you could certainly drop to a long for iOS as you’ll never exceed that in reality. The example uses long … Read more

How to create directory using Swift code (NSFileManager)

Swift 5.0 let paths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true) let documentsDirectory = paths[0] let docURL = URL(string: documentsDirectory)! let dataPath = docURL.appendingPathComponent(“MyFolder”) if !FileManager.default.fileExists(atPath: dataPath.path) { do { try FileManager.default.createDirectory(atPath: dataPath.path, withIntermediateDirectories: true, attributes: nil) } catch { print(error.localizedDescription) } } Swift 4.0 let paths = NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.documentDirectory, FileManager.SearchPathDomainMask.userDomainMask, true) let documentsDirectory: AnyObject = paths[0] as AnyObject … Read more

Testing file existence using NSURL

NSURL does have this method: – (BOOL)checkResourceIsReachableAndReturnError:(NSError **)error Which “Returns whether the resource pointed to by a file URL can be reached.” NSURL *theURL = [NSURL fileURLWithPath:@”/Users/elisevanlooij/nonexistingfile.php” isDirectory:NO]; NSError *err; if ([theURL checkResourceIsReachableAndReturnError:&err] == NO) [[NSAlert alertWithError:err] runModal];

Create a folder inside documents folder in iOS apps

I do that the following way: NSError *error; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; // Get documents folder NSString *dataPath = [documentsDirectory stringByAppendingPathComponent:@”/MyFolder”]; if (![[NSFileManager defaultManager] fileExistsAtPath:dataPath]) [[NSFileManager defaultManager] createDirectoryAtPath:dataPath withIntermediateDirectories:NO attributes:nil error:&error]; //Create folder

How to detect total available/free disk space on the iPhone/iPad device?

UPDATE: Since a lot of time has passed after this answer and new methods/APIs have been added, please check the updated answers below for Swift etc; Since I’ve not used them myself, I can’t vouch for them. Original answer: I found the following solution working for me: -(uint64_t)getFreeDiskspace { uint64_t totalSpace = 0; uint64_t totalFreeSpace … Read more

Is there any way to see the file system on the iOS simulator?

UPDATE: Since iOS 8: ~/Library/Developer/CoreSimulator/Devices The location used to be: ~/Library/Application Support/iPhone Simulator It had directories for all models of simulators (4.0, 4.1, 5.0, etc) you have ever run, go to the one you are running from in Xcode. Once in a folder, go to Applications, choose the Finder option that shows date for files, … Read more