nsfilemanager

Get array of directories in documents directory

Hi, 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 ...

Calculate the size of a folder...

Just a quick one... I'm creating a folder to cache images inside Documents with my iPhone App. I want to be able to keep the size of this folder down to 1MB, so I need to to check the size in bytes of my folder. I have code to calculate the size of file, but I need the size of the folder. What would be the best way to do this? Will ...

What are the limitations on filenames saved to the iPhone?

I can't seem to find any documentation on this. Is there a limit to the number of characters that can be used in a filename and/or is there a restriction on what characters can be used in a file name saved by an iPhone app? Thanks. ...

NSFileSystemFreeSize

Hi, I get a negaitve number from trying to use this function can anyone help. see code below NSDictionary *fileAttributes = [fileManager attributesOfItemAtPath:dbPath error:Error]; NSDictionary *fileSysAttributes = [fileManager fileSystemAttributesAtPath:dbPath]; NSNumber *FileSize = [fileAttributes objectForKey:NSFileSize]; NSNumber...

iPhone: How to Write an Image to Disk in the App Directories

I am working on an iPhone project in which I need save camera images to disk and file but the code below fails: (**** -(void)imagePickerController:(UIImagePickerController *) picker didFinishPickingMediaWithInfo:(NSDictionary *)info { [picker dismissModalViewControllerAnimated:YES]; imageView.image = [info objectForKey:@"UIImagePicker...

Why does NSFileManager return TRUE on fileExistsAtPath when there is no such file?

NSFilemanager is returning true for the following, when there should not be any such file there yet. What is happening? if([myManager fileExistsAtPath:[[self documentsDirectory] stringByAppendingPathComponent:@"Music/songlist.txt"]]){ NSLog(@"file is there"); } ...

Detect file creation date on iPhone OS?

I was planning on writing some code whose logic was based upon testing the creation date of a particular file in my app's Documents folder. Turns out, when I call -[NSFileManager attributesOfItemAtPath:error:], NSFileCreationDate isn't one of the provided attributes. Is there no way to discover a file's creation date? Thanks. ...

Plist won't copy to documents directory

I have a plist file in my resources group in xcode. I am trying to copy this into my documents directory on app launch. I am using the following code (taken from a sqlite tutorial): BOOL success; NSError *error; NSFileManager *fileManager = [NSFileManager defaultManager]; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentD...

Can't delete a file created by mkstemp() on Mac OS X

Apparently, NSFileManager is unable to delete files created by mkstemp(). Here's some test code to demonstrate this: char pathCString[] = "/tmp/temp.XXXXXX"; int fileDescriptor = mkstemp(pathCString); if (fileDescriptor == -1) { NSLog(@"mkstemp failed"); } else { close(fileDescriptor); NSURL *url = [NSURL URLWithString:[NSSt...

Saving data - does work on Simulator, not on Device

I use NSData to persist an image in my application. I save the image like so (in my App Delegate): - (void)applicationWillTerminate:(UIApplication *)application { NSLog(@"Saving data"); NSData *data = UIImagePNGRepresentation([[viewController.myViewController myImage]image]); //Write the file out! NSArray *paths = NSSe...

I need to load a video stored in Applications folder in to a UITableView ?

I need to load a video stored in Applications folder in to a table view. When I touched the cell the video plays. I used the following code to get all the video files in to an array. NSFileManager *fileManager = [NSFileManager defaultManager]; NSArray* contents = [fileManager directoryContentsAtPath:@"/Users/srikanth/Desktop/...

iPhone: Invalid Characters in filesystem

Hi, is the iPhone's filesystem or the use of NSFilemanager restricted to any characters or is everything allowed (this is what I'm currently assuming after doing some research). ...

iPhone Simulator - Writing to File/Reading problems

I have been reading alot on iPhone read/writing and I believe that everything I have is correct but for some reason it isn't working the way it should. code is as follows NSString *docsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; NSString *filePath = [docsDirectory str...

NSFileManager crashing in app delegate

I have this code in a method called from applicationDidFinishLaunching. It works in the simulator, but crashes on the iPhone. There are about 1,600 2KB mp3 files being copied in this operation. If I try to instantiate the app multiple times, it will eventually copy more each time until the app eventually will start without crashing. I am...

Getting content-type for a file in ObjectiveC

Hi All, How to get the Content-Type for any file in ObjectiveC ? I can then set the "Content-Type" header while sending the file to any web server. Thanks ...

NSFileManager delete contents of directory

How do you delete all the contents of a directory without deleting the directory itself? I want to basically empty a folder yet leave it (and the permissions) intact. ...

Count files in directories AND subdirectories? iPhone

I am trying to count entire files in a directory, including subdirectories. This is what I have to count files in the first folder: -(NSString *)numberOfPhotos { NSString *MyPath = @"/rootdirectory/"; NSArray *directoryContent = [[NSFileManager defaultManager] directoryContentsAtPath:MyPath]; return [NSString stringWithFo...

NSFileManager - Copying Files at Startup

Hi, I need to copy a few sample files from my app's resource folder and place them in my app's document folder. I came up with the attached code, it compiles fine but it doesn't work. All the directories I refer to do exist. I'm not quite sure what I am doing wrong, could someone point me in the right direction please? NSFileManager*ma...

On iPhone, how do I check once per day to see if i should phone-home?

I want to check a file on the server only once each day (NSURL). And, no matter if I fetch the file or not, I do not run the function (to check for the file) again that day. This would SEEM easy... but I forsee issues. Say I had created a directory under the mainBundle: "/Library/runOnceEachDay/". Perhaps I could write to /Library/ru...

use of NSFilemanager

Hello, I am working as an Iphone developer since 5 months but never ever i have used NSfilemanager class. Apple has documentation but still i am not cleared about its use. My question is that can anybody tell me(with example) how and when to use the NSfilemanager class ? Any help will be appreciated. Thanks. ...