nsfilemanager

Finding file's size

雨燕双飞 提交于 2019-11-27 11:25:39
In my iPhone app I am using the following code to find a file's size. Even though the file exists, I am seeing zero for the size. Can anyone help me? Thanks in advance. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *URL = [documentsDirectory stringByAppendingPathComponent:@"XML/Extras/Approval.xml"]; NSLog(@"URL:%@",URL); NSError *attributesError = nil; NSDictionary *fileAttributes = [[NSFileManager defaultManager] attributesOfItemAtPath:URL error:&attributesError]; int fileSize

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

旧城冷巷雨未停 提交于 2019-11-27 10:04:17
Is there any way to browse the file system of a currently running or just killed iOS simulator? I'd settle for being able to see a specific app's files if there's a way to do that. Note that I don't want to do this programatically. I want to see/open the files in the Finder. Kendall Helmstetter Gelner 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

What's a quick way to test to see a file exists?

最后都变了- 提交于 2019-11-27 09:31:03
问题 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. 回答1: Swift v3: let fileExists = FileManager.default.fileExists(atPath: somePath) Thanks to Nikolay Suvandzhiev. Objective-C (Original): BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath

Swift: failing to copy files to a newly created folder

 ̄綄美尐妖づ 提交于 2019-11-27 09:09:19
I'm building a simple program in Swift, it should copy files with a certain extension to a different folder. If this folder exist the program will just copy them in the folder, if the folder doesn't exist, the program has to make it first. let newMTSFolder = folderPath.stringByAppendingPathComponent("MTS Files") if (!fileManager.fileExistsAtPath(newMTSFolder)) { fileManager.createDirectoryAtPath(newMTSFolder, withIntermediateDirectories: false, attributes: nil, error: nil) } while let element = enumerator.nextObject() as? String { if element.hasSuffix("MTS") { // checks the extension var

Iterate through files in a folder and its subfolders using Swift's FileManager

无人久伴 提交于 2019-11-27 06:31:50
I'm quite new to programming a Swift and I'm trying to iterate through the files in a folder. I took a look at the answer here and tried to translate it to Swift syntax, but didn't succeed. let fileManager = NSFileManager.defaultManager() let enumerator:NSDirectoryEnumerator = fileManager.enumeratorAtPath(folderPath) for element in enumerator { //do something } the error I get is: Type 'NSDirectoryEnumerator' does not conform to protocol 'SequenceType' My aim is to look at all the subfolders and files contained into the main folder and find all the files with a certain extension to then do

Get all folders of URL

拜拜、爱过 提交于 2019-11-27 05:32:33
Hi I'm trying to read all files from a given server. What I want to do: Read all the folders Get the file URLs inside the folders I tried this to get the folders and filey of my server, but it returned me an array with the folders of my MacBook: NSURL *directory = [NSURL URLWithString:@"linktoserver"]; NSFileManager *fileManager = [NSFileManager defaultManager]; NSError *error = nil; self.contentList = [[NSArray alloc] initWithArray:[fileManager contentsOfDirectoryAtURL:directory includingPropertiesForKeys:[[NSArray alloc] initWithObjects:NSURLNameKey, nil] options

How to check if a file exists in Documents folder?

谁说我不能喝 提交于 2019-11-27 02:25:23
I have an application with In-App Purchase, that when the user buy something, download one html file into the Documents folder of my app. Now I must check if this HTML file exists, so if true, load this HTML file, else load my default html page. How I can do that? With NSFileManager I can't get outside of mainBundle .. Nikolai Ruhe Swift 3: let documentsURL = try! FileManager().url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true) ... gives you a file URL of the documents directory. The following checks if there's a file named foo.html: let fooURL = documentsURL

Easy way to get size of folder (ObjC/Cocoa)?

两盒软妹~` 提交于 2019-11-27 02:24:44
问题 Right now I'm using this code to get the size of a folder: NSArray *contents; NSEnumerator *enumerator; NSString *path; contents = [[NSFileManager defaultManager] subpathsAtPath:folderPath]; enumerator = [contents objectEnumerator]; while (path = [enumerator nextObject]) { NSDictionary *fattrib = [[NSFileManager defaultManager] fileAttributesAtPath:[folderPath stringByAppendingPathComponent:path] traverseLink:YES]; fileSize +=[fattrib fileSize]; } [contents release]; [path release]; The

iPhone (iOS): copying files from main bundle to documents folder error

浪子不回头ぞ 提交于 2019-11-27 01:42:00
问题 I am trying to copy some files across from my app bundle to the documents directory on first launch. I have the checks in place for first launch, but they're not included in code snippet for clarity. The problem is that I am copying to the documents directory (which already exists) and in the documentation, it states that: dstPath must not exist prior to the operation. What is the best way for me to achieve the copying straight to the documents root? The reason I want to do this is to allow

Create a folder inside documents folder in iOS apps

馋奶兔 提交于 2019-11-26 23:27:52
I just want to create new folders in the documents folder of my iPhone app. Does anybody know how to do that? Appreciate your help! Vladimir 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