nsfilemanager

Array of multiple URL's NSFileManager Swift

允我心安 提交于 2019-11-28 00:36:05
How would I go about adding multiple URL's? I wonder how I can set that up into an array with swift. if let audioUrl = NSURL(string: "http://freetone.org/ring/stan/iPhone_5-Alarm.mp3") { println("LOADING AUDIO") if let myAudioDataFromUrl = NSData(contentsOfURL: audioUrl){ println("AUDIO LOADED") let documentsUrl = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)[0] as NSURL let destinationUrl = documentsUrl.URLByAppendingPathComponent(audioUrl.lastPathComponent!) println(destinationUrl) if NSFileManager().fileExistsAtPath(destinationUrl.path!) {

Why is NSDirectoryEnumerator picking up hidden files here?

删除回忆录丶 提交于 2019-11-27 19:31:16
问题 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

NSFileManager creating folder (Cocoa error 513.)

╄→尐↘猪︶ㄣ 提交于 2019-11-27 18:49:17
I'm trying to create a folder inside the /sounds folder of my app. -(void)productPurchased:(UAProduct*) product { NSLog(@"[StoreFrontDelegate] Purchased: %@ -- %@", product.productIdentifier, product.title); NSFileManager *manager = [NSFileManager defaultManager]; NSString *bundleRoot = [[NSBundle mainBundle] bundlePath]; NSError *error; NSString *dataPath = [NSString stringWithFormat:@"%@/sounds/%@", bundleRoot, product.title]; if (![manager fileExistsAtPath:dataPath isDirectory:YES]) { [manager createDirectoryAtPath:dataPath withIntermediateDirectories:YES attributes:nil error:&error]; NSLog

How to overwrite a file with NSFileManager when copying?

 ̄綄美尐妖づ 提交于 2019-11-27 18:06:55
I'm using this method to copy a file: [fileManager copyItemAtPath:sourcePath toPath:targetPath error:&error]; I want to overwrite a file when it exists already. The default behavior of this method is to throw an exception/error "File Exists." when the file exists. There's no option to specify that it should overwrite. So what would be the safest way to do this? Would I first check if the file exists, then delete it, and then attempt to copy? This has the danger that the app or device goes OFF right in the nanosecond after the file has been deleted but the new file hasn't been copied to that

Get directory contents in date modified order

ⅰ亾dé卋堺 提交于 2019-11-27 17:42:48
Is there an method to get the contents of a folder in a particular order? I'd like an array of file attribute dictionaries (or just file names) ordered by date modified. Right now, I'm doing it this way: get an array with the file names get the attributes of each file store the file's path and modified date in a dictionary with the date as a key Next I have to output the dictionary in date order, but I wondered if there's an easier way? If not, is there a code snippet somewhere which will do this for me? Thanks. nall's code above pointed me in the right direction, but I think there are some

How To Get Directory Size With Swift On OS X

一世执手 提交于 2019-11-27 17:03:08
问题 I am trying to get the size of a directory, as well as it's content on OS X using Swift. So far, I have only been able to get the size of the directory itself, with none of it's content. For most of my directories it generally shows a value of 6,148 bytes but it does varie. I have tried the directorySize() function from the file below but it returned 6,148 bytes as well. https://github.com/amosavian/ExtDownloader/blob/2f7dba2ec1edd07282725ff47080e5e7af7dabea/Utility.swift I tried the top 2

Save file in document directory in swift 3?

醉酒当歌 提交于 2019-11-27 14:27:34
问题 I am saving files in a document directory in swift 3 with this code: fileManager = FileManager.default // let documentDirectory = fileManager?.urls(for: .documentDirectory, in: .userDomainMask).first as String var path = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] as String path = path + name let image = #imageLiteral(resourceName: "Notifications") let imageData = UIImageJPEGRepresentation(image, 0.5) let bool = fileManager?.createFile(atPath: path,

iOS9 Swift File Creating NSFileManager.createDirectoryAtPath with NSURL

那年仲夏 提交于 2019-11-27 13:29:45
Before iOS9, we had created a directory like so let documentsPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as! String let logsPath = documentsPath.stringByAppendingPathComponent("logs") let errorPointer = NSErrorPointer() NSFileManager.defaultManager().createDirectoryAtPath(logsPath, withIntermediateDirectories: true, attributes: nil, error: errorPointer) But with iOS9 they removed String.stringByAppendingPathComponent. The auto convert tool replaced our use of String with NSURL. createDirectoryAtPath() takes a string so I need to convert the NSURL to

Displaying file copy progress using FSCopyObjectAsync

故事扮演 提交于 2019-11-27 13:18:03
问题 It appears after much searching that there seems to be a common problem when trying to do a file copy and show a progress indicator relative to the amount of the file that has been copied. After spending some considerable time trying to resolve this issue, I find myself at the mercy of the StackOverflow Gods once again :-) - Hopefully one day I'll be among those that can help out the rookies too! I am trying to get a progress bar to show the status of a copy process and once the copy process

iOS: How do you find the creation date of a file?

与世无争的帅哥 提交于 2019-11-27 11:47:52
I'm trying to find the creation date (NOT modification date) of a file. Creation date doesn't appear to be in the attributes of a file, though modified date is. I'm using this code.. NSFileManager* fm = [NSFileManager defaultManager]; NSString* path = [PathHelpers pathInDocumentsFolderWithFilename:FILE_NAME]; NSDictionary* attrs = [fm attributesOfItemAtPath:path error:nil]; if (attrs != nil) { return (NSDate*)[attrs objectForKey: NSFileCreationDate]; } else { return nil; } This always returns nil. Typing 'po attrs' into the debugger to get the list of key/value pairs in the NSDictionary