nsfilemanager

How can I tell if a symbolic link exists at a certain path?

梦想与她 提交于 2020-01-04 01:59:08
问题 I have an original file, /path/to/foo.txt , and a symbolic link to it, /other/path/to/foo.txt . I delete /path/to/foo.txt , but leave the symbolic link in-place. How can I tell that the symbolic link still exists using Cocoa APIs? I found this by using the standard/recommended FileManager.fileExists(atPath:). The problem here, for anyone unfamiliar with that API, is that it traverses symlinks. So, when I do this: FileManager.default.fileExists(atPath: "/other/path/to/foo.txt") it returns

Delete all files and folder from a certain folder

自作多情 提交于 2020-01-03 01:59:20
问题 I have a /Documents/Images folder , in that folder are several other folders named after years , in those folders i have images. I want to delete everything from the images folder ( including the folders and the images in these folders). I tried several code snippets but none delete the folders my method: - (void) clearCache:(NSString *) folderName{ NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectoryPath = [paths

Using NSOutlineView as a file browser, starting from a given directory

徘徊边缘 提交于 2020-01-02 21:05:12
问题 I've been following this tutorial for using NSOutlineView as a hierarchical file browser: https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/OutlineView/Articles/UsingOutlineDataSource.html I used all the code in the tutorial and it worked. However, I then tried to call initWithPath: with a path other than / and it doesn't work: the fullPath of the top item (i.e. the folder specified in initWithPath ) is just the name of the folder, and the children method of the

Error deleting contents in directory - Domain=NSCocoaErrorDomain Code=4 | Domain=NSPOSIXErrorDomain Code=2 “No such file or directory”

谁都会走 提交于 2020-01-02 19:28:20
问题 How can I fix the following errors when running the code below? I already searched in SO but can't find anything for Swift 3. // Delete all files in given directory let path = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0] as String let dataPath = NSURL(fileURLWithPath: path) if let enumerator = FileManager.default.enumerator(atPath: dataPath.path!) { while let fileName = enumerator.nextObject() as? String { do { try FileManager.default.removeItem(atPath: "\

NSURL isFileURL always returns NO

心已入冬 提交于 2020-01-01 04:20:27
问题 Can someone explain to me why the following code: NSString* filePathString = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0]; NSLog(@"%i", [[NSURL URLWithString:filePathString] isFileURL]); NSLog(@"%@", filePathString); outputs: 0 "/var/mobile/Applications/28ADFC19-874C-4304-94B5-F6441CAE9FAD/Documents" This means that this url isn't a file URL. Obviously, it is. Background: I'm trying to use an AVCaptureMovieFileOutput to write a movie recording to a file,

Get the list of files from selected folders having sizes >100MB with their paths objective c

孤人 提交于 2019-12-31 07:28:07
问题 I want to get the list of all files with their paths & sizes for my mac system. From that, I want to filter only those files which have file size above 100 MB. I got the size of my system using the below code. NSError *error; NSFileManager *fileManager = [NSFileManager defaultManager]; NSDictionary *fileAttributes = [fileManager attributesOfFileSystemForPath:@"/" error:&error]; Now I want to get the list of files with their paths and sizes. I searched a lot but those couldn't meet to my

iPhone - file properties

孤人 提交于 2019-12-31 05:30:28
问题 i m creating an application which makes the iphone work as a pendrive for easy file sharing purpose. In the first stage, i have some files(png, pdf, jpg, zip) in a directory and i made them display in the tableview in the form of mutable array. It displays in the tableView as shown below, .DS_Store .localized gazelle.pdf Hamburger_sandwich.jpg IITD TAJ Picture 028_jpg.jpg iya_logo_final_b&w.jpg manifesto09-eng.pdf RSSReader.sql SimpleURLConnections.zip SQLTutorial I just want to display the

iOS , Copying files from Inbox folder to Document path

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-30 11:29:07
问题 I enabled Document Types to import or copy files from other apps to my application. I have some questions : 1- Where should create the method of moving files form Inbox to Document directory ? is this the right place ? func applicationWillEnterForeground(_ application: UIApplication) 2- On first view controller I am getting files from Document directory : func getFileListByDate() -> [String]? { let directory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first! if

iphone copying folder from bundle to documents

青春壹個敷衍的年華 提交于 2019-12-29 02:10:11
问题 I'm having the hardest time getting this to work. I'm trying to copy a folder from my bundle to the documents directory. the folder I'm trying to find is here: ...app/Resources/12/(a bunch of jpgs) NSString *myPath = [[[NSBundle mainBundle] resourcePath]stringByAppendingPathComponent:@"12"]; NSLog(@"%@",myPath);/// returns "..../MyApp.app/12" NSArray *arrayOf12s = [[NSFileManager defaultManager]contentsOfDirectoryAtPath:myPath error:nil]; NSLog(@"%@",arrayOf12s); ////always returns NULL 回答1:

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

[亡魂溺海] 提交于 2019-12-28 10:05:11
问题 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? 回答1: 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:^{