Tag: nsfilemanager

Error while checking if a file exists

I’m trying to write to a plist file using writeToFile, before I write I check whether the file exists. This is the code: #import “WindowController.h” @implementation WindowController @synthesize contacts; NSString *filePath; NSFileManager *fileManager; – (IBAction)addContactAction:(id)sender { NSDictionary *dict =[NSDictionary dictionaryWithObjectsAndKeys: [txtFirstName stringValue], @”firstName”, [txtLastName stringValue], @”lastName”, [txtPhoneNumber stringValue], @”phoneNumber”, nil]; [arrayContacts addObject:dict]; [self updateFile]; } […]

How do I verify a file's existence in iCloud?

I know that the file exists, because I can download it, but I need to check to see whether it exists. I have tried using [NSFileManager contentsOfDirectoryAtPath:error:] but it gives me null. I don’t understand why that is because I can still download the files that I’m looking for. Maybe it’s an incorrect URL, but […]

CPU raises with attributesOfItemAtPath:error:

I am using [NSFileManager attributesOfItemAtPath:error:] function for fetching attributes of file. But sometimes my application cpu is going upto 100%. I am using this function for 100k(approx.) files. Sample of my application: 2128 -[NSFileManager attributesOfItemAtPath:error:] 2128 +[NSFileAttributes _attributesAtPath:partialReturn:filterResourceFork:error:] 2123 _attributesAtPath 2072 listxattr 29 realloc 18 realloc 11 szone_size 22 _attributesAtPath 5 _sysenter_trap Can anyone please […]

Does File Attribute contain millisecond? Objective -c

I would like to get milliseconds from creation time of file attribute When I get file attribute, I use NSDateFormatter to convert file creation time (NSDate) to NSString. [dateFormatter setDateFormat:@”yyyy-MM-dd HH:mm:ss:SS: A”]; ss –> seconds SS –> should be millisecond A –> milliseconds of the date I get 00 for SS and get 54487000 for […]

How to get Remote File Last-Modification Date

I need to get the file modification date of a remote file. Obviously, attributes in this example returns NULL: – (BOOL) fileHasBeenModifiedSinceLastLaunch { NSError * err = nil; NSDictionary * attributes = [FILEMANAGER attributesOfItemAtPath:[NSURL URLWithString:@”http://www.wrightscs.com/some_file.txt”] error:&err]; NSString * modified = [NSString stringWithFormat:@”%@”,[attributes objectForKey:@”NSFileModificationDate”]]; NSString * savedmod = [[NSUserDefaults standardUserDefaults] objectForKey:@”kFeedLastModified”]; NSLog(@”Error: %@”,[err localizedDescription]); NSLog(@”Saved Modified […]

Disable backup of documents folder and all its sub folders on icloud?

I have an already running enterprise application which stores a lot of documents inside the documents folders. I wish to disable the iCloud backup of all these documents and folders inside the Documents folder. The problem is that the contents inside the folder keep on changing dynamically and the idea of adding kCFURLIsExcludedFromBackupKey for every […]

Download font .ttf file from web and store on iPhone

Is it possible to download .ttf file from web and store it on iPhone. Then use that for for labels and all other stuff ? Because my client want to control fonts from database and don’t want to just drop fonts to xcode project right away. So in future if he wants to change font, […]

How to display file copy progress in 10.8

FSCopyObjectAsync is Deprecated in OS X v10.8, Now how to display progress indictor for file copy operation.

Rename file in Cocoa?

How would I rename a file, keeping the file in the same directory? I have a string containing a full path to a file, and a string containing a the new filename (and no path), for example: NSString *old_filepath = @”/Volumes/blah/myfilewithrubbishname.avi”; NSString *new_filename = @”My Correctly Named File.avi”; I know about NSFileManager’s movePath:toPath:handler: method, but […]

Cocoa – NSFileManager removeItemAtPath Not Working

I am trying to delete a file, but somehow nsfilemanager will not allow me to do so. I do use the file in one line of code, but once that action has been ran, I want the file deleted. I have logged the error code and message and I get error code: 4 and the […]