nsfilemanager

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 NSFileMa...

Sort NSFileManager Results

Hi Everyone: I am wondering how to get a NSFileManager listing to display the results in the order that the Finder sorts them. By default, this code: NSFileManager *fileManager = [[NSFileManager alloc] init]; NSError *foundErrors = nil; NSArray *contentsOfDockDirectory = [fileManager contentsOfDirectoryAtPath:@"/Users/me/Desktop err...

NSFileManager works fine on simulator but not on device

Hi, I have problem creating directories and files with NSFileManager on the iPhone device. My code, shown below, works fine on the simulator, but not on the device, could you please help me? Gimme some directions where the problem may be, thanks for every reply.. I'm first creating directories this way: NSFileManager *fileMgr = [NSFile...

iPhone: NSFilemanager fileExistsAtPath:isDirectory: not working properly?

I'm working on an app for jailbroken iPhones. I'm trying to get only the directories of an folder. so I'm doing this: NSArray *contentOfFolder = [[NSFileManager defaultManager] directoryContentsAtPath:path]; NSLog(@"contentOfFolder: %@", contentOfFolder); directoriesOfFolder = [[NSMutableArray alloc] initWithCapacity:100]; for (NSStrin...

How do I get an NSArray of filenames of all files in a given directory in my app?

What I want to do seems simple enough: Get an array of filenames in a given "directory" on my app. But the more I play around with NSFileManager and NSBundle I find myself getting more lost...I just want to get the filenames of the files organized in a specific directory in my iPhone Xcode project...For example: The directory in question...

Easy way to get size of folder (ObjC/Cocoa) ?

Right now I'm using this code to get the size of a folder: NSArray *contents; NSEnumerator *enumerator; NSString *path; contents = [[NSFileManager defaultManager] subpathsAtPath:folderPath]; enumerator = [contents objectEnumerator]; while (path = [enumerator nextObject]) { NSDictionary *fattrib = [[NSFileM...

Find all Folders in Root Directory

Hi, I am developing an application in cocoa.I need to search all songs in selectyed folder.I used "subpathsAtPath" to get all the components in selected folder. This works fine if the user selects a particular folder like /User/Music.But if the user selects root directory like "/" then this method hangs .Is there any way to resolve this...

[Cocoa/ObjC] Find parent directory of a path

Is there any way to find the parent directory of a path using NSFileManager or something? e.g. Take this: /path/to/something And turn it into /path/to/ Thanks ...

[Objective c] create a directory in the iPhone

What's wrong with that? #define AUDIO_NOTES_FOLDER [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/myApp/Pictures"] NSFileManager *NSFm= [NSFileManager defaultManager]; BOOL isDir=YES; if(![NSFm fileExistsAtPath:FILEPATH isDirectory:&isDir]) if(![NSFm createDirectoryAtPath:FILEPATH attributes:nil]) NSLog(@"E...

Error while checking if a file exists

Hi, 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 =[NSDicti...

Get directory contents in date modified order

Is there an method to get the contents of a folder in a particular order? I'd like an array of file attribute dictionaries (or just file names) ordered by date modified. Right now, I'm doing it this way: get an array with the file names get the attributes of each file store the file's path and modified date in a dictionary with the d...

How to check if a file exists in Documents folder?

Hi guys, I have an application with In-App Purchase, that when the user buy something, download one html file into the Documents folder of my app. Now I must check if this HTML file exists, so if true, load this HTML file, else load my default html page. How I can do that? With NSFileManager i can't get outside of mainBundle.. Thanks ...

Creating files in Objective-C

Hi all, Which is the faster way of creating files ? Case 1: ====== NSData *data = [Some data]; [data writeToFile:filePath atomically:YES]; Case 2: ======= NSFileManager *fileManager = [NSFileManager defaultManager]; [fileManager createFileAtPath:filePath contents:data attributes:nil]; Thanks Biranchi ...

Saving video from UIImagePickerController

In my application, the user can record a video using the UIImagePickerController, and I need to save it to disk for later use. I've gotten the path out of the info dictionary and I'm going to save it to my documents directory, but the problem I'm having is that the URL passed in the dictionary is just that - a URL and not a file path. Wh...

List Directory Contents in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { Profile_ManagerAppDelegate *appDelegate = [[U...

Cocoa + CopyItemAtPath: toPath: fails when copying a folder from a removable storage to local machine

Hi Guys I am trying to copy a folder from removable storage device to the local machine and i am using the function from NSFileManager class "copyItemAtPath: toPath:". It fails and the error description i get is as follows: Error Domain=NSPOSIXErrorDomain Code=1 UserInfo=0x12f49d90 "Operation could not be completed. Operation not permit...

Testing file existence using NSURL

Snow Leopard introduced many new methods to use NSURL objects to refer to files, not pathnames or Core Services' FSRefs. However, there's one task I can't find a URL-based method for: Testing whether a file exists. I'm looking for a URL-based version of -[NSFileManager fileExistsAtPath:]. Like that method, it should return YES if the UR...

How do I safely move / swap files in Cocoa?

In a cocoa app of mine, there is a method that does some operations on a sqlite database's schema that could be destructive, so first we make a rollback copy of the database, and if there's an error, we call the following method to replace the db file with the rollback file. Note that I definitely want the db file replaced with the rollb...

Showing File Copy Status on a Progress Bar

Hello, I am trying to perform a low-level file copy but also display my progress using a determinate progress bar. Is there any way I can do this? I have looked on many mail archives, and one blog post explaining on how to do it in carbon which didn't work for me. ...

Am I crazy? Help with NSFileManager delegate method shouldProceedAfterError in 10.5+

So I'm kind of a Cocoa n00b, but I'm writing this simple little program and I can't get the NSFileManager delegate method "shouldProceedAfterError..." to fire. Here's the code I'm running in my AppDelegate -(BOOL)copyFile { [[NSFileManager defaultManager] setDelegate:self]; NSError *copyError = nil; NSString *filename = [[N...