nsfilemanager

Swift: failing to copy files to a newly created folder

本小妞迷上赌 提交于 2019-12-17 09:52:52
问题 I'm building a simple program in Swift, it should copy files with a certain extension to a different folder. If this folder exist the program will just copy them in the folder, if the folder doesn't exist, the program has to make it first. let newMTSFolder = folderPath.stringByAppendingPathComponent("MTS Files") if (!fileManager.fileExistsAtPath(newMTSFolder)) { fileManager.createDirectoryAtPath(newMTSFolder, withIntermediateDirectories: false, attributes: nil, error: nil) } while let element

Is there any way to see the file system on the iOS simulator?

*爱你&永不变心* 提交于 2019-12-17 08:02:42
问题 Is there any way to browse the file system of a currently running or just killed iOS simulator? I'd settle for being able to see a specific app's files if there's a way to do that. Note that I don't want to do this programatically. I want to see/open the files in the Finder. 回答1: UPDATE: Since iOS 8: ~/Library/Developer/CoreSimulator/Devices The location used to be: ~/Library/Application Support/iPhone Simulator It had directories for all models of simulators (4.0, 4.1, 5.0, etc) you have

How can I calculate the size of a folder?

匆匆过客 提交于 2019-12-17 02:08:49
问题 I'm creating a folder to cache images inside Documents with my iPhone App. I want to be able to keep the size of this folder down to 1MB, so I need to to check the size in bytes of my folder. I have code to calculate the size of file, but I need the size of the folder. What would be the best way to do this? 回答1: tl;dr All the other answers are off :) Problem I'd like to add my two cents to this old question as there seem to be many answers that are all very similar but yield results that are

How to detect total available/free disk space on the iPhone/iPad device?

丶灬走出姿态 提交于 2019-12-16 19:58:49
问题 I'm looking for a better way to detect available/free disk space on the iPhone/iPad device programmatically. Currently I'm using the NSFileManager to detect the disk space. Following is the snippet of the code which does the job for me: -(unsigned)getFreeDiskspacePrivate { NSDictionary *atDict = [[NSFileManager defaultManager] attributesOfFileSystemForPath:@"/" error:NULL]; unsigned freeSpace = [[atDict objectForKey:NSFileSystemFreeSize] unsignedIntValue]; NSLog(@"%s - Free Diskspace: %u

How to detect total available/free disk space on the iPhone/iPad device?

倾然丶 夕夏残阳落幕 提交于 2019-12-16 19:57:00
问题 I'm looking for a better way to detect available/free disk space on the iPhone/iPad device programmatically. Currently I'm using the NSFileManager to detect the disk space. Following is the snippet of the code which does the job for me: -(unsigned)getFreeDiskspacePrivate { NSDictionary *atDict = [[NSFileManager defaultManager] attributesOfFileSystemForPath:@"/" error:NULL]; unsigned freeSpace = [[atDict objectForKey:NSFileSystemFreeSize] unsignedIntValue]; NSLog(@"%s - Free Diskspace: %u

NSFileManager.defaultManager().fileExistsAtPath returns false instead of true

一世执手 提交于 2019-12-16 19:54:25
问题 How is it possible? let exists = NSFileManager.defaultManager().fileExistsAtPath(path.absoluteString) print("exists: \(exists)") //false This is path.absoluteString //file:///Users/kuna/Library/Developer/CoreSimulator/Devices/92BD140D-5C14-43C4-80D6-904BB9594ED6/data/Containers/Data/Application/5B818832-BB19-4047-A7F8-1487F36868D6/Documents/wishlists/68/147/128/IMG_0006.PNG And you can see it is there where it should be: What is going on? 回答1: (The code in this answer has been updated for

Swift: How to expand a tilde in a path String

独自空忆成欢 提交于 2019-12-14 03:40:41
问题 How can I expand a path String with a tilde in Swift? I have a string like "~/Desktop" and I'd like to use this path with the NSFileManager methods, which requires the tilde to be expanded to "/Users/<myuser>/Desktop" . (This question with a clear problem statement doesn't exist yet, this should be easily findable. Some similar but not satisfying questions are Can not make path to the file in Swift, Simple way to read local file using Swift?, Tilde-based Paths in Objective-C) 回答1: Tilde

check Filename is exist by prefix in Swift

£可爱£侵袭症+ 提交于 2019-12-13 23:35:11
问题 I want to check whether my filename with just prefix is exist or not in Swift. E.g My file name is like Companies_12344 So after _ values are dynamic but "Companies_" is static. How can i do that? My code below For split func splitFilename(str: String) -> (name: String, ext: String)? { if let rDotIdx = find(reverse(str), "_") { let dotIdx = advance(str.endIndex, -rDotIdx) let fname = str[str.startIndex..<advance(dotIdx, -1)] println("splitFilename >> Split File Name >>\(fname)") } return nil

how to Display Files From Files Sharing in Swift 3

荒凉一梦 提交于 2019-12-13 15:47:51
问题 A added File Sharing in Plist in My app So I can Easily Copy Files when The iPhone has connect with iTunes to my mac But the problem is that when I copy some files with iTunes in my App and Run the app I have 2 Problems : 1- when I stop the app and open that again I can't see any files in iTunes in the file sharing part 2- This code Below here should print file Exists if there is file and print some thing else if there isn't file But Just Print File Exists here is my codes if filemgr

NSFileManager moveItemAtPath issue

萝らか妹 提交于 2019-12-13 06:35:33
问题 I am using NSFileManager to move items from one file path to another file path but it results in an exception.But i dont get exception every time, the exception is raised only after second or third time of loading the urls Exception Error Domain=NSCocoaErrorDomain Code=4 "The operation couldn’t be completed. (Cocoa error 4.)" UserInfo=0x631a900 {NSUserStringVariant=Move, NSFilePath=/Users/cgvak/Library/Application Support/iPhone Simulator/4.3/Applications/3731EEFB-03F8-4E0B-BF5D-A94BEE0D2DE2