nsfilemanager

Array of NSStrings from filenames within a folder?

坚强是说给别人听的谎言 提交于 2019-12-22 01:21:11
问题 I'm trying to create an array of NSStrings of the contents of a folder that I've dragged into my project... but when I count the items in the array afterwards, it's always comes back with 0; So, my folder in my project looks like this -Cards -Colors Blue.png Green.png Orange.png Yellow.png Purple.png Black.png And my code which tries to get this list of files (the color pngs) is NSError *error = nil; NSString *pathString = [[NSString alloc] init]; pathString = [[NSString alloc] initWithString

NSFileManager list directory contents excluding directories

做~自己de王妃 提交于 2019-12-21 17:29:54
问题 Is there a way to tell the -[NSFileManager contentsOfDirectoryAtURL:includingPropertiesForKeys:options:error:] method to exclude directory names when gathering the contents of a directory? I have a tree view showing folders and want to show ONLY files in the table view, but I can't seem to find a key or any other way to exclude folders. I suppose I could iterate the returned array to stuff only files into a second array, which will be used as the data source, but this double-handling seems a

Delete file obj c

倖福魔咒の 提交于 2019-12-21 06:50:55
问题 I am creating files with the following code NSString *docPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]; NSString *filename = @"xyz123.data"; docPath = [NSString stringWithFormat:@"%@/%@", docPath, filename]; NSError *error = nil; [data writeToFile:docPath options:0 error:&error]; To delete files I use the following NSFileManager *manager = [NSFileManager defaultManager]; NSError *error = nil; NSString *path = @"xyz123.data"; //NSString *path = @"Documents/xyz123.data"

How to write Dictionary to a file?

不打扰是莪最后的温柔 提交于 2019-12-21 03:15:41
问题 I have a FileHelper class where I've implemented 3 methods whose job is to write a Dictionary contents to a file. Those methods are: func storeDictionary(_ dictionary: Dictionary<String, String>, inFile fileName: String, atDirectory directory: String) -> Bool { let ext = "txt" let filePath = createFile(fileName, withExtension: ext, atDirectory: directory) /**** //If I use this method, file is created and dictionary is saved guard (dictionary as NSDictionary).write(to: filePath!, atomically:

iPhone/iPad: Unable to copy folder from NSBundle to NSDocumentDirectory

孤者浪人 提交于 2019-12-20 15:27:23
问题 I am trying to copy a folder in my NSBundle which contains quite a number of images. I tried doing it with these codes. NSFileManager *fileManager = [NSFileManager defaultManager]; NSError *error; NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *documentDBFolderPath = [documentsDirectory stringByAppendingPathComponent:@"Images"]; NSString *resourceDBFolderPath = [[[NSBundle

How to overwrite a folder using [NSFileManager defaultManager] when copying?

大兔子大兔子 提交于 2019-12-20 12:09:16
问题 Using the line below, [fileManager copyItemAtPath:sourcePath toPath:targetPath error:&error]; We can copy a folder but if the folder already exists it throws an exception "File Exists". In order to overwrite a single file, we can achieve it through the following lines: NSData *myData = [NSData dataWithContentsOfURL:FileURL]; /fetch single file [myData writeToFile:targetPath atomically:YES]; But I want to copy an already existing folder i.e, overwrite . Edit : Simple Possibility , I can remove

How to rename directories?

百般思念 提交于 2019-12-20 10:14:05
问题 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. 回答1: NSString *oldDirectoryPath = @"Type your old directory Path"; NSArray *tempArrayForContentsOfDirectory =[[NSFileManager defaultManager] contentsOfDirectoryAtPath:oldDirectoryPath error:nil]; NSString *newDirectoryPath = [[oldDirectoryPath stringByDeletingLastPathComponent]stringByAppendingPathComponent

How do I verify a file's existence in iCloud?

不问归期 提交于 2019-12-19 11:59:17
问题 I know that the file exists, because I can download it, but I need to check to see whether it exists. I have tried using [NSFileManager contentsOfDirectoryAtPath:error:] but it gives me null. I don't understand why that is because I can still download the files that I'm looking for. Maybe it's an incorrect URL, but the URL that I'm using is the one that I printed at creation of my UIDocument that I'm looking for. Maybe I'm using the wrong method? EDIT: I have also tried using NSMetadataQuery,

NSFileProtectionComplete for iOS 4.0 apps

心已入冬 提交于 2019-12-19 08:06:16
问题 I saw a WWDC 2010 video about NSFileProtectionComplete and protecting app's data. Are there any examples out there? Does any one have sample code to share? 回答1: See the NSFileManager class doc: The file is stored in an encrypted format on disk and cannot be read from or written to while the device is locked or booting. It's basically file vault for individual files. You just pass the constant when you set the file attributes. To mark a file as protected, you must add an extended attribute to

NSFileProtectionComplete for iOS 4.0 apps

倾然丶 夕夏残阳落幕 提交于 2019-12-19 08:06:10
问题 I saw a WWDC 2010 video about NSFileProtectionComplete and protecting app's data. Are there any examples out there? Does any one have sample code to share? 回答1: See the NSFileManager class doc: The file is stored in an encrypted format on disk and cannot be read from or written to while the device is locked or booting. It's basically file vault for individual files. You just pass the constant when you set the file attributes. To mark a file as protected, you must add an extended attribute to