nsfilemanager

FileManager cannot find audio file

北城余情 提交于 2019-12-04 05:29:33
问题 Helloo! My ultimate goal is to create a UITableViewController with recordings made in-app, using FileManager to traverse the /Documents/ directory and list all the recordings found there. The recording and playback are functioning just fine with one recording, with the following setup: // In VC#1 func setupRecorder(){ let audioSession:AVAudioSession = AVAudioSession.sharedInstance() do { try audioSession.setCategory(AVAudioSessionCategoryPlayAndRecord) } catch { print("Audio Setup Error: \

Get all URLs for resources in sub-directory in Swift

末鹿安然 提交于 2019-12-04 04:32:52
I am attempting to create an array of URLs for all of the resources in a sub-directory in my iOS app. I can not seem to get to the correct path, I want to be able to retrieve the URLs even if I do not know the names (i.e. I don't want to hard code the file names into the code). Below is a screen shot of the hierarchy, I am attempting to get all the files in the 'test' folder: Any help is greatly appreciated, I have attempted to use file manager and bundle main path but to no joy so far. This is the only code I have currently: let fileManager = FileManager.default let path = Bundle.main.urls

Swift: How to expand a tilde in a path String

只愿长相守 提交于 2019-12-04 02:45:50
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 ) Tilde expansion Swift 1 "~/Desktop".stringByExpandingTildeInPath Swift 2 NSString(string: "~/Desktop")

Able to write/read file but unable to delete file SWIFT

限于喜欢 提交于 2019-12-04 01:40:58
问题 I store an .jpg image i the iOS documents directory. I can write files and read files but when it comes to deleting them it says that there is no such file but that cannot be because I can read it with the same url. Reading: let paths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true) let path = NSURL(fileURLWithPath: paths[0] as String) let fullPath = path.appendingPathComponent(info["pi"] as! String) let data = NSData(contentsOf: fullPath!) Deleting: let

Delete file obj c

妖精的绣舞 提交于 2019-12-03 22:20:50
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"; [manager path error:&error]; But neither the first nor the second path seem to work, I always get the

NSURLSessionDownloadTask move temporary file

混江龙づ霸主 提交于 2019-12-03 18:13:52
问题 I'm trying to reach the file which I was downloading earlier by NSURLSession . It seems I can't read the location of the file, even though I'm doing it before delegate method ends (as the file is temporary). Still, I'm getting nil when trying to access the data under location returned from NSURLSession delegate and error 257. The code goes as following: - (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTask *)downloadTask didFinishDownloadingToURL:(NSURL *)location

How to obtain the size of a Application Directory in iPhone?

拥有回忆 提交于 2019-12-03 15:45:00
(NSString *) getApplicationUsage{ double directorySizeInBytes = 0.0f; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationDirectory, NSUserDomainMask, YES); NSString *pathStr = [paths objectAtIndex:0]; pathStr = [pathStr stringByDeletingLastPathComponent]; //REMOVE THE LAST PATH COMPONENT i.e /Applications NSDirectoryEnumerator *enumrator = [[NSFileManager defaultManager] enumeratorAtPath:pathStr]; for (NSString *itemPath in enumrator) { itemPath = [pathStr stringByAppendingPathComponent:itemPath]; NSDictionary *attr = [[NSFileManager defaultManager] attributesOfItemAtPath

How to check whether a file is locked in Cocoa?

依然范特西╮ 提交于 2019-12-03 13:55:21
问题 Is there any API to check whether a file is a locked? I am not able to find any API in the NSFileManager class.Let me know if there is any API to check the lock of the file. I found the following link related to file lock http://lists.apple.com/archives/cocoa-dev/2006/Nov/msg01399.html I can invoke – isWritableFileAtPath: on file. Is there any other way to find whether a file is locked? 回答1: Following Code worked for me. NSError * error; NSDictionary *attributes = [[NSFileManager

Get array of directories in documents directory

会有一股神秘感。 提交于 2019-12-03 13:03:52
问题 I am trying to return the list of directories present in an app's Documents directory. I am able to get an array containing all files of a given extension (eg .txt files or .png files) and am able to return all contents (including directories). The problem arises when I want to return only the directories. Is there a simple way of doing this? Here is my code for returning all .txt files: - (ViewController *) init { if (self = [super init]) self.title = @"Text Files"; // get the list of .txt

File access in a sandboxed Mac app with swift

时光总嘲笑我的痴心妄想 提交于 2019-12-03 12:53:20
问题 I am working on an app for OS X 10.9 with swift, sandboxed. The app needs access to a SQLite database file. I let the user choose/open a file with NSOpenPanel. I then save the file path with NSUserDefaults for later use. I want this file to be opened automatically every time when the app is started again. I get the stored path from the NSUserDefault, but when I open the file with this path I get an error, saying I have no permission to access the file. (it is working without sandboxing) It