nsfilemanager

NSFileManager delete contents of directory

孤者浪人 提交于 2019-12-03 02:18:03
问题 How do you delete all the contents of a directory without deleting the directory itself? I want to basically empty a folder yet leave it (and the permissions) intact. 回答1: E.g. by using a directory enumerator: NSFileManager *fileManager = [[NSFileManager alloc] init]; NSDirectoryEnumerator *enumerator = [fileManager enumeratorAtPath:path]; NSString *file; while (file = [enumerator nextObject]) { NSError *error = nil; BOOL result = [fileManager removeItemAtPath:[path

iOS Memory issue (ARC) when downloading and saving large ammount of images from server

断了今生、忘了曾经 提交于 2019-12-03 00:43:06
The following code downloads 700+ images from a server with varying sizes, the issue here is that memory (even with ARC) is never released and eventually a memory warning appears followed by the application exiting. I've tried @autoreleasepool in this method and that didn't seem to work. Also I've tried stopping the for loop at different locations to see if memory is released after it finished, but it isn't. This method is called inside a for loop and receives the image url and short name. It has been tried in a background thread and main thread with the same results (memory wise). -(void

Create a Custom Formatted Dictionary Array from CSV File of Data

ぐ巨炮叔叔 提交于 2019-12-02 23:39:29
问题 I've created an iPhone app that has a dictionary array of locations (lat,long,point). I created the array by manually entering each value. myLocationArray = @[ @{ kStation : @"1", kLatitude : @( 41.656467), kLongitude : @(-81.277963) }, @{ kStation : @"2", kLatitude : @(41.657118), kLongitude : @(-81.276545) }, @{ kStation : @"3", kLatitude : @(41.658493), kLongitude : @(-81.273542) }, ... This is good and works but now I want to create this array programmatically by getting the data from a

How to rename directories?

99封情书 提交于 2019-12-02 21:14:33
I have created a folder within the Documents folder in my application directory . I wanted to rename that folder through code,but not able to understand how to do it. Please help me out. NSString *oldDirectoryPath = @"Type your old directory Path"; NSArray *tempArrayForContentsOfDirectory =[[NSFileManager defaultManager] contentsOfDirectoryAtPath:oldDirectoryPath error:nil]; NSString *newDirectoryPath = [[oldDirectoryPath stringByDeletingLastPathComponent]stringByAppendingPathComponent:newDirectoryname]; [[NSFileManager defaultManager] createDirectoryAtPath:newDirectoryPath attributes:nil];

What is the best way to remove logs file Core Data creates, when removing a UIManagedDocument from iCloud?

夙愿已清 提交于 2019-12-02 20:02:57
问题 I would have thought NSFileManager s method of removeItemAtURL:error: would remove the Core Data log files created when using UIManagedDocuments with iCloud. What is the best way to make sure all of these log files are removed? 回答1: I have used... - (void)deleteRemnantsOfOldDatabaseDocumentAndItsTransactionLogsWithCompletionHandler:(completion_success_t)completionBlock { __weak CloudController *weakSelf = self; NSURL *databaseStoreFolder = self.iCloudDatabaseStoreFolderURL; NSURL

NSFileManager: removing item

血红的双手。 提交于 2019-12-02 18:06:33
问题 The problem is removing an item that´s been written using writeToFile: method, I cannot seem to remove it. I tried NSFileManager but I guess these are two different types of storage. - (BOOL) removeObject: (NSString *)objectToRemove inCategory:(StorageType)category { BOOL result = NO; NSError *removeError; NSString *storageFolder = [self getCategoryFor:category]; if (objectToRemove) { NSFileManager *fileManager = [[NSFileManager alloc]init]; // Find folder NSArray *paths =

NSFileManager delete contents of directory

旧时模样 提交于 2019-12-02 15:48:32
How do you delete all the contents of a directory without deleting the directory itself? I want to basically empty a folder yet leave it (and the permissions) intact. Georg Fritzsche E.g. by using a directory enumerator: NSFileManager *fileManager = [[NSFileManager alloc] init]; NSDirectoryEnumerator *enumerator = [fileManager enumeratorAtPath:path]; NSString *file; while (file = [enumerator nextObject]) { NSError *error = nil; BOOL result = [fileManager removeItemAtPath:[path stringByAppendingPathComponent:file] error:&error]; if (!result && error) { NSLog(@"Error: %@", error); } } Swift let

Handle multiple swift errors in one catch block

橙三吉。 提交于 2019-12-02 14:56:19
问题 I have a question about the swift error handling. In my swift Script I have to do multiple things with the FileManager that could throw an exception. Now my first thought was, to put them all in one do-catch block. do { let fileManager = FileManager.default try fileManager.moveItem(atPath: destination, toPath: "\(destination).old") try fileManager.createDirectory(atPath: destination, withIntermediateDirectories: false) ... } catch { print(error) exit(EXIT_FAILURE) } The problem now is, that I

iPhone - file properties

烂漫一生 提交于 2019-12-02 12:19:42
i m creating an application which makes the iphone work as a pendrive for easy file sharing purpose. In the first stage, i have some files(png, pdf, jpg, zip) in a directory and i made them display in the tableview in the form of mutable array. It displays in the tableView as shown below, .DS_Store .localized gazelle.pdf Hamburger_sandwich.jpg IITD TAJ Picture 028_jpg.jpg iya_logo_final_b&w.jpg manifesto09-eng.pdf RSSReader.sql SimpleURLConnections.zip SQLTutorial I just want to display the name of the files and i do not want to display the extensions. I know that it is possible to extract the

Can't play file from documents in AVAudioPlayer

霸气de小男生 提交于 2019-12-02 07:59:00
问题 I have a file on documents folder of app and I want to play it. if NSFileManager.defaultManager().fileExistsAtPath(pathString) { let url = NSURL(fileURLWithPath:pathString, isDirectory: false) do { let player = try AVAudioPlayer(contentsOfURL:url) player.prepareToPlay() player.play() } catch let error as NSException { print(error) } catch {} } There is a file on file system and I checked its existence. Also all lines in do block are executed. There is neither exception nor error and still no