nsfilemanager

Overwriting the previous file in NSDocumentDirectory

旧街凉风 提交于 2019-12-11 06:16:57
问题 I have used this code to write a string to the same file 10 times . But it is overwriting the previous data for every new launch. I want to append the new data to the old data . [@"one" writeToFile:[self returnDocumentsDirectory] atomically:NO encoding:NSASCIIStringEncoding error:nil]; -(NSString *)returnDocumentsDirectory { NSArray *DocumentsDirectoryPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *path = [DocumentsDirectoryPath objectAtIndex

I'm trying to find a file size. But my length is equl to zero

余生颓废 提交于 2019-12-11 05:46:36
问题 I'm trying to find a file size. NSFileHandle *output = [NSFileHandle fileHandleForWritingAtPath:self.finalPath]; //seek to begin of the file [output seekToFileOffset:0]; NSData *mydata = [output availableData]; NSLog(@"length: %d", [mydata length]); But my length is equl to zero. Why? 回答1: availableData is for reading files. If you just want to find out the size of a file, you don't actually have to open it. Just use NSFileManager like this: NSDictionary *attributes = [[NSFileManager

Getting metadata by NSFileManager

给你一囗甜甜゛ 提交于 2019-12-11 05:14:28
问题 I am working with NSFileManager and I am able to get the file's last update, creation date, ... but I am not able to get when was the last time the file was opened. Is there any way to get this information? And other question, I get the MIME by the pathExtension property, but this way I get for example .pdf, .doc, ... instead of application/pdf, application/doc, text/txt, audio/vmw, ...is any way to get this information automatically? Thanks a lot! 回答1: Use Spotlight's MDItem API to get all

createFileAtPath & OCUnit & errno blues

随声附和 提交于 2019-12-11 03:08:39
问题 I looked here and there but to no avail. Consider: - (void) write: (NSString *) xId data:(NSData *) data forClass: (Class) c { NSFileManager * fm = [NSFileManager defaultManager] ; NSString * instancePath = [self instancePath:xId forClass: c] ; errno = 0 ; BOOL success = [fm createFileAtPath: instancePath contents: data attributes: nil] ; if (!success) { ::NSLog(@"Couldn't write to path: %@", instancePath) ; ::NSLog(@"Error was code: %d - message: %s", errno, strerror(errno)); } else { :

Check if file is alias Swift

梦想与她 提交于 2019-12-10 23:37:50
问题 How can I check if a file is an Alias on Mac? Here is my code so far: public func getFiles(){ let folderPath = "/Users/timeBro/Desktop/testfolder" let fileManager = NSFileManager.defaultManager() let enumerator:NSDirectoryEnumerator = fileManager.enumeratorAtPath(folderPath)! for url in enumerator.allObjects { let newurl = NSURL(string: url as! String) print("\(url as! String)") print(url); print(newurl?.isFileReferenceURL()) } } How can I check if the file is and alias? 回答1: Update : I

Move file and override [duplicate]

此生再无相见时 提交于 2019-12-10 14:16:02
问题 This question already has answers here : How to overwrite a file with NSFileManager when copying? (9 answers) Closed 3 years ago . I'm trying to move a file even if a file with the same name already exists. NSFileManager().moveItemAtURL(location1, toURL: location2) Does NSFileManager 's method moveItemAtURL have an override option? How can I replace the existing file? 回答1: You can always check if the file exists in the target location. if it does, delete it and move your item. Swift 2.3 let

Document Creation with UIDocumentBrowserViewController

百般思念 提交于 2019-12-10 13:41:45
问题 The documentation for documentBrowser(_:didRequestDocumentCreationWithHandler:) says, "Create a new document and save it to a temporary location. If you use a UIDocument subclass to create the document, you must close it before calling the importHandler block." So I created a file URL by taking the URL for the user's temporary directory ( FileManager.default.temporaryDirectory ) and appending a name and extension (getting a path like "file:///private/var/mobile/Containers/Data/Application

“No such file or directory” Error when creating directory

六月ゝ 毕业季﹏ 提交于 2019-12-10 13:36:00
问题 I am attempting to save thumbnails of user generated photos in a subdirectory in the documents directory, but I am unable to create the subdirectory in the first place. When I attempt to create the subdirectory in the documents directory I get this error (No such file or directory): Error Domain=NSCocoaErrorDomain Code=4 "The operation couldn’t be completed. (Cocoa error 4.)" UserInfo=0x17ef9c90 {NSFilePath=/var/mobile/Applications/FD0CC480-97FE-4E50-931F-5341DB6AD92B/Documents/com.Jonathan

NSFileManager creating directory error 518 NSFileWriteUnsupportedSchemeError

坚强是说给别人听的谎言 提交于 2019-12-10 12:30:53
问题 I was trying to create a directory NSError*error=nil; NSString* BIDirectory=[[NSSearchPathForDirectoriesInDomains(NSCachesDirectory,NSUserDomainMask,YES) objectAtIndex:0] stringByAppendingPathComponent:@"BI"]; BOOL isDir,flag=YES; //if the directory doesn't exist create it. if(!([[NSFileManager defaultManager] fileExistsAtPath:BIDirectory isDirectory:&isDir]&& isDir)) flag=[[NSFileManager defaultManager] createDirectoryAtURL:[NSURL URLWithString:BIDirectory] withIntermediateDirectories:YES

Download file to Folder in iPhone

为君一笑 提交于 2019-12-10 12:02:31
问题 I am new to iPhone, I made app in which, when user downloads anything it gets downloaded into DocumentDirectory I wants downloading inside my folder which i have created in DocumentDirectory How to achieve this ? I thought I will download file to my DocumentDirectory and i will move that file to my folder inside DocumentDirectory . Is it good practice ? Here is my code snippet, But still i am unable to move my file. - (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*