nsfilemanager

Performance of deleting folder with lots of files on iOS

故事扮演 提交于 2019-12-10 09:27:28
问题 Say I've got a folder in my iOS app's data directory with several thousand small files in it. Deleting this folder (via [NSFileManager removeItemAtPath] ) takes a nontrivial amount of time. But on OS X, deleting a folder with the same contents is very fast. It seems to simply unlink the folder from the filesystem. So why does iOS take so long? What is the difference? Edit: On an iPad 3, deleting 3 folders with 5,000 to 9,000 files each takes about 35 seconds. On the simulator running on an

iOS: How to delete all existing files with specific extension from the documents dir?

一个人想着一个人 提交于 2019-12-09 18:01:16
问题 When I update my iOS app, I want to delete any existing sqlite databases in the Documents directory. Right now, on an application update, I copy the database from the bundle to the documents directory and name it by appending the bundle version. So, on the update, I also want to delete any old versions that might exist. I just want to be able to delete all sqlite files, without having to loop through and look for ones from previous versions. Is there any way to wildcard the removeFileAtPath:

How to add or import multiple items to a file which saved in Documents Directory with Swift?

妖精的绣舞 提交于 2019-12-09 04:13:31
As you can see, here is how to add a word "hello" to a Test.txt (saved in Documents Directory of an app): let documentsDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first! let archiveURL = documentsDirectory.appendingPathComponent("Test").appendingPathExtension("txt") try! Data("hello".utf8).write(to: archiveURL) Suppose I have a txt or csv file (with 300 names saved one by one in line: Picture1), which is saved in iCloud Drive or somewhere. How can I add those names to the Test.txt file (saved in Documents Directory of an app) with one time, just the

I want to crete a zip file with multiple images in it and get the entire zip file and send to sftp server

让人想犯罪 __ 提交于 2019-12-08 14:25:59
问题 I am trying create a zip file from the contents of another directory in NSdcomentDirectory. I am using "SSZipArchive" for this. But When I try to get the zip file its not available.Here is my code which I am trying. ` NSString *stringPath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)objectAtIndex:0]stringByAppendingPathComponent:@"/SourceFolder"]; NSString *stringPath2 = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES

iPhone: How to Write an Image to Disk in the App Directories

喜你入骨 提交于 2019-12-08 13:18:44
问题 I am working on an iPhone project in which I need save camera images to disk and file but the code below fails: (************ -(void)imagePickerController:(UIImagePickerController *) picker didFinishPickingMediaWithInfo:(NSDictionary *)info { [picker dismissModalViewControllerAnimated:YES]; imageView.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"]; imgglobal =imageView.image; NSString *newFilePath = [NSHomeDirectory() stringByAppendingPathComponent: @"~/Users/abc/Library

What is the hexadecimal part in the Documents folder's path?

大城市里の小女人 提交于 2019-12-08 12:51:31
I have a file located in my app's Documents folder. When the app is terminated I save the file's URL in the AppDelegate's applicationWillTerminate method: // archiver init code [archiver encodeObject:file.URL forKey:kFileURL]; // finish encoding and write data to file system But when trying to restore the file on the next app launch the file manager cannot locate the file: After calling NSURL *fileURL = [unarchiver decodeObjectForKey:kFileURL]; NSString *filePath = fileURL.path; the method [[NSFileManager defaultManager] fileExists:filePath]; returns NO . I tried to find the reason for this

createDirectoryAtPath:attributes: alternative

心已入冬 提交于 2019-12-08 07:43:01
问题 [NSFileManager createDirectoryAtPath:attributes:] gives me a warning that it is depreciated. What is the alternative? Or is there a better way of doing this? Thanks Tom 回答1: Use createDirectoryAtPath:withIntermediateDirectories:attributes:error: P.S. createIntermediates If YES, then the method will also create any necessary intermediate directories; if NO, then the method fails if any parent of the directory to be created does not exist. In addition, if you pass NO for this parameter, the

How to add or import multiple items to a file which saved in Documents Directory with Swift?

断了今生、忘了曾经 提交于 2019-12-08 03:49:15
问题 As you can see, here is how to add a word "hello" to a Test.txt (saved in Documents Directory of an app): let documentsDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first! let archiveURL = documentsDirectory.appendingPathComponent("Test").appendingPathExtension("txt") try! Data("hello".utf8).write(to: archiveURL) Suppose I have a txt or csv file (with 300 names saved one by one in line: Picture1), which is saved in iCloud Drive or somewhere. How can I add

removeItemAtPath dosn't work on the device

本小妞迷上赌 提交于 2019-12-08 03:11:51
问题 I'v been struggling with this one for some time so any hint or suggestion are welcome. I'm trying to delete a file from a directory under "Documents". The problem is that the file is not delete on the device dow it is on the simulator. Just to add to the mystery, before the call to removeItemAtPath I check if the file exists with fileExistsAtPath, and even display the list of files under that folder. Attached the code for deletion: // Override to support editing the table view. - (void

iOS Application Library directory <uid> always gets changed

血红的双手。 提交于 2019-12-07 22:26:07
问题 After reading Apple documentation, I used URLsForDirectory to obtain the Library destination within my app, and my objective is to download content from a hosted service & cache it in the Library folder, so that User cannot interact with the contents through iTunes. NSArray *docPaths= [[NSFileManager defaultManager] URLsForDirectory:NSLibraryDirectory inDomains:NSUserDomainMask]; NSLog(@"%@",[docPaths description]); NSString *docPath=[(NSURL *)[docPaths objectAtIndex:0] path]; docPath =