Questions tagged [nsfilemanager]

The NSFileManager class enables you to perform various generic file-system operations and insulates an application from the underlying file system.

An apple class reference.

A simple file handling

//Gives you document folder detail

    NSFileManager *fileManager = [NSFileManager defaultManager];
    [fileManager setDelegate:self];
    NSError *error;
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSArray *newfilelist=[fileManager contentsOfDirectoryAtPath:documentsDirectory error:&error ];

//gives your file is file or directory

NSString *path = @"/Users";
    NSFileManager *fileManager = [NSFileManager defaultManager];
    NSLog(@"fileManager=%@", fileManager);
    BOOL bDirectory;
    BOOL bExists = [fileManager fileExistsAtPath:path isDirectory:&bDirectory];
    NSLog(@"%@: bExists=%d bDirectory=%d", path, bExists, bDirectory);
1453 questions
0
votes
2 answers

iOS : I can't find my file?

I have this arborescence: Project Folder build Project ProjectTests Pictures In the sub-folder "Project" I have the AppDelegate and a file called "Alert.txt". I want to access that text file from my AppDelegate so I tried…
Rob
  • 15,732
  • 22
  • 69
  • 107
0
votes
1 answer

Directory not persisting between iOS app launches

So I'm trying to store some data between openings of an app I'm making, but for some reason the directory I'm making and the data I'm storing aren't persisting between app openings, and I can't figure out why… I have three methods: - (NSString…
The Awesome Guy
  • 322
  • 5
  • 15
0
votes
2 answers

Programmatically determine file content type on OSX

I am working with files whose content format has changed over multiple versions of OSX, previously it was ASCII, then JSON, now a binary plist. So I need to determine what kind of file it is so I can parse it either as text, using the JSON APIs, or…
brianpartridge
  • 763
  • 8
  • 19
0
votes
1 answer

Moving file created by shell script in Mac application

I'm having trouble moving a file created by a shell script in my Mac application. The file seems to be saved in: /Users/USERNAME/Library/Developer/Xcode/DerivedData/APPLICATION_NAME/Build/Products/Debug/ I have tried using the NSFileManager as…
Cristian
  • 6,765
  • 7
  • 43
  • 64
0
votes
1 answer

how to delete the contents of a folder in obj c

i used the following method to delete all the contents of the folder NSFileManager *fm = [NSFileManager defaultManager]; NSArray* arrFilePath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *…
Ravi
  • 1,759
  • 5
  • 20
  • 38
0
votes
1 answer

Delete multiple files with names containing a substring efficiently

I would like to delete multiple files that contain a substring. Say for example I would like to delete all the files that has the substring my. Assume that my directory contains 4 files: photo.jpg, myPhoto.jpg, beachMyPhoto.jpg, anyPhoto.jpg, since…
antf
  • 3,162
  • 2
  • 26
  • 33
0
votes
3 answers

how to detect existence of large file in iOS?

At runtime, my app downloads some large video files and plays them. They are large, so I figure they might get wiped at any time by the system trying to recover memory. I had trouble using [fileManager fileExistsAtPath: pathOfVideo]: Then I found…
Thunder Rabbit
  • 5,405
  • 8
  • 44
  • 82
0
votes
1 answer

Cocoa Error 256 when getting file list in application resources folder

The following code is outputting The operation couldn’t be completed. (Cocoa error 256.) and the filenames NSArray is null/empty. There should be files in this folder, any ideas whats broken? NSError *error; NSFileManager *fm = [NSFileManager…
Kurru
  • 14,180
  • 18
  • 64
  • 84
0
votes
2 answers

Crash when storing NSMutableArray with NSFilemanager

So I#m trying to save an array to a file. This should be done in the following code but by calling the addProjectsObject method, the program crashes withe the following error code: ***** Terminating app due to uncaught exception…
user1242094
  • 107
  • 2
  • 10
0
votes
3 answers

archiveRootObject:toFile: file looks like gibberish

I'm trying to write my NSMutableArray to a text file. I looked at the data with NSLog before I write it, and it's in the format I want String \t integer \t integer \t integer \r\n String \t integer \t integer \t integer \r\n ... (50 lines like…
Crystal
  • 28,460
  • 62
  • 219
  • 393
0
votes
0 answers

nsfilemanager attributesOfItemAtPath returns just a generic filetype

I need to determine the filetype at a given path, without having a file-extension. I thought that attributesOfItemAtPath would give me needed information, but this just returns the value NSFileTypeRegular - wow... Is there any way to figure out the…
Swissdude
  • 3,486
  • 3
  • 35
  • 68
0
votes
1 answer

Getting wrong Available Startup Disk Space for Mac 10.6 and above

I am using following code to get the available disk space of the startup disk. NSFileManager *fm = [NSFileManager defaultManager]; double freeSpace = 0.0; NSDictionary *attr = [[NSFileManager defaultManager] attributesOfFileSystemForPath:@"/"…
Vikram Singh
  • 1,726
  • 1
  • 13
  • 25
0
votes
1 answer

copyItemAtPath, moveItemAtPath, and createFileAtPath all seem to create a file that's unreadable

So I'm trying to figure out why I can't make a copy of my file that's readable. I've tried moveItemAtPath, copyItemAtPath, and createFileAtPath. Each time, reading the data from the original path works fine but reading it from the new file path…
valheru
  • 2,552
  • 3
  • 20
  • 40
0
votes
2 answers

Difference between writing a file to plist and NSFilemanager

Is there any difference between writing an objects(ex array types and NSObject types) to plist and NSFileManager. if so can i write 1000's of images data and mp3 songs to plist.
user1300511
  • 91
  • 2
  • 11
0
votes
1 answer

Unable to write NSMutableArray to NSFileManager iOS Sdk

i wrote below code to write the nsmutablearray to filemanager. NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; // the path to write…
user1300511
  • 91
  • 2
  • 11