nsfilemanager

Why is NSDirectoryEnumerator picking up hidden files here?

回眸只為那壹抹淺笑 提交于 2019-11-28 13:58:52
i need to avoid hidden files in this enumeration, but .DS_Store files are still being added. i put in the NSLog to check, and i am getting output there. there's probably something obvious, but i can't see it. NSDirectoryEnumerator *dirEnumerator; NSFileManager *fileManager = [[NSFileManager alloc] init]; dirEnumerator = [fileManager enumeratorAtURL:item includingPropertiesForKeys:[NSArray array] options:NSDirectoryEnumerationSkipsPackageDescendants || NSDirectoryEnumerationSkipsHiddenFiles errorHandler:nil]; for (NSURL *urlItem in dirEnumerator) { // is item hidden ? NSNumber *isHidden = nil;

Download file from server using Swift

℡╲_俬逩灬. 提交于 2019-11-28 10:14:02
Hi I have a whole bunch of .mp3 files I want to use with NSFileManager and store in the documents folder. Is there a way I can download the .mp3 files online and then have it save to the documents folder? This is what I'm using for a local file. let filemanager = NSFileManager.defaultManager() let documentsPath : AnyObject = NSSearchPathForDirectoriesInDomains(.DocumentDirectory,.UserDomainMask,true)[0] let destinationPath:NSString = documentsPath.stringByAppendingString("/Attention.mp3") if (!filemanager.fileExistsAtPath(destinationPath)) { var theError: NSError? let fileForCopy = NSBundle

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

会有一股神秘感。 提交于 2019-11-28 09:49:45
I am trying to set up my application so that on first launch, a series of files located in the "Populator" folder in the main bundle are copied into the documents directory. My current implementation is as follows: - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { NSString *documentsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; NSString *sourcePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"Populator"]; NSString *folderPath =

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

余生长醉 提交于 2019-11-28 08:43:31
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 problem is that its highly innacurate. It either adds a few megabytes or deducts a few megabytes from the

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

匆匆过客 提交于 2019-11-28 07:03:31
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 iTunes file sharing support. - (BOOL)application:(UIApplication *)application

iPhone - How to create a custom album and give custom names to photos in camera roll programmatically?

风流意气都作罢 提交于 2019-11-28 05:29:55
I am developing an iPhone photo application, so i need to create a separate album with a name "My Album" in camera roll and i need to save my UIImageView image with custom name for example "My Image.png" inside the newly created directory. How can i do this? You can create a custom album and add an image pretty easy with these lines of code in iOS: // Create the new album. __block PHObjectPlaceholder *myAlbum; [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{ PHAssetCollectionChangeRequest *changeRequest = [PHAssetCollectionChangeRequest creationRequestForAssetCollectionWithTitle:title];

Disable backup of documents folder and all its sub folders on icloud?

只谈情不闲聊 提交于 2019-11-28 04:31:28
问题 I have an already running enterprise application which stores a lot of documents inside the documents folders. I wish to disable the iCloud backup of all these documents and folders inside the Documents folder. The problem is that the contents inside the folder keep on changing dynamically and the idea of adding kCFURLIsExcludedFromBackupKey for every files sounds a bit difficult, as there are multiple classes in my code which can write to the documents directory. Is there any way I can

Read/write file in Documents directory problem

血红的双手。 提交于 2019-11-28 04:27:01
问题 I am trying to write a very basic text string to my documents directory and work from there to later save other files etc. I am currently stuck with it not writing anything into my Documents directory (In my viewDidLoad ) NSArray *pathArray = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) NSString *documentsDirectory = [pathArray objectAtIndex:0]; NSString *textPath = [documentsDirectory stringByAppendingPathComponent:@"file1.txt"]; NSString *text = @"My cool

Testing file existence using NSURL

五迷三道 提交于 2019-11-28 04:03:08
Snow Leopard introduced many new methods to use NSURL objects to refer to files, not pathnames or Core Services' FSRefs. However, there's one task I can't find a URL-based method for: Testing whether a file exists. I'm looking for a URL-based version of -[NSFileManager fileExistsAtPath: ] . Like that method, it should return YES if the URL describes anything, whether it's a regular file, a directory, or anything else. I could attempt to look up various resource values , but none of them are explicitly guaranteed to not exist if the file doesn't, and some of them (e.g., NSURLEffectiveIconKey )

Why NSMutableDictionary don't want write to file?

百般思念 提交于 2019-11-28 01:38:44
问题 - (void)viewDidLoad { [super viewDidLoad]; if ([[NSFileManager defaultManager] fileExistsAtPath:pathString]) { infoDict = [[NSMutableDictionary alloc] initWithContentsOfFile:pathString]; } else { infoDict = [[NSMutableDictionary alloc]initWithObjects:[NSArray arrayWithObjects:@"BeginFrame",@"EndFrame", nil] forKeys:[NSArray arrayWithObjects:[NSNumber numberWithBool:YES],[NSNumber numberWithBool:YES], nil]]; if ([infoDict writeToFile:pathString atomically:YES]) { NSLog(@"Created"); } else {