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
49
votes
7 answers

Swift 3.0 FileManager.fileExists(atPath:) always return false

When I use method .fileExists(atPath:)to judge whether the file is exist in file system, the method always return false to me. I checked the file system and the file do exist. Here is my code: let filePath = url?.path var isDir : ObjCBool =…
Dean Lee
  • 781
  • 2
  • 7
  • 13
44
votes
4 answers

Document folder iOS Simulator

How is possible to find quickly the document folder (in the mac) of an App when I'm using the simulator? When I need to explore the document folder during the simulation of the App now I use a variable of the App to find the document folder path and…
Lorenzo
  • 3,293
  • 4
  • 29
  • 56
44
votes
3 answers

Storing images locally on an iOS device

Some iOS photo-related apps store images created with the app somewhere other than the photo library. For example Fat Booth shows a scrolling list of photos created with the app at app start-up. Note these photos are persisted w/o the user…
SundayMonday
  • 19,147
  • 29
  • 100
  • 154
43
votes
10 answers

iOS: How do you find the creation date of a file?

I'm trying to find the creation date (NOT modification date) of a file. Creation date doesn't appear to be in the attributes of a file, though modified date is. I'm using this code.. NSFileManager* fm = [NSFileManager defaultManager]; NSString*…
Ben Clayton
  • 80,996
  • 26
  • 120
  • 129
42
votes
3 answers

Save file in document directory in swift 3?

I am saving files in a document directory in swift 3 with this code: fileManager = FileManager.default // let documentDirectory = fileManager?.urls(for: .documentDirectory, in: .userDomainMask).first as String var path =…
TechChain
  • 8,404
  • 29
  • 103
  • 228
41
votes
4 answers

How to rename a file using NSFileManager

I have a single file named a.caf in the documents directory. I would like to rename it when user types into a UITextField and presses change (the text entered in the UITextField should be the new filename). How can I do this?
Mike
  • 737
  • 1
  • 6
  • 14
36
votes
5 answers

How to use iCloud to store and sync app files

I already have an iPhone App that stores data in a file in the local documents folder. Now I learnt about iCloud technologies and my first question was: is there a way to use iCloud as a directory when sometimes I check for new versions? I mean: can…
albianto
  • 4,092
  • 2
  • 36
  • 54
36
votes
9 answers

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.
Vervious
  • 5,559
  • 3
  • 38
  • 57
36
votes
6 answers

iphone - how to check if the file is a directory , audio , video or image?

Following my program shows contents of Documents directory and is displayed in a tableView . But the Documents directory contains some directories , some audio , some video , and some images etc . NSArray *dirPaths =…
Subbu
  • 2,063
  • 4
  • 29
  • 42
36
votes
3 answers

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/
indragie
  • 18,002
  • 16
  • 95
  • 164
34
votes
5 answers

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…
nevan king
  • 112,709
  • 45
  • 203
  • 241
30
votes
3 answers

iOS9 Swift File Creating NSFileManager.createDirectoryAtPath with NSURL

Before iOS9, we had created a directory like so let documentsPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0] as! String let logsPath = documentsPath.stringByAppendingPathComponent("logs") let errorPointer =…
Moemars
  • 4,692
  • 3
  • 27
  • 30
30
votes
4 answers

Getting bundle file references / paths at app launch

Suppose I have an arbitrary set of files included in the Main App Bundle. I would like to fetch the file URLs for those at launch and store them somewhere. Is this possible using NSFileManager? The documentation is unclear in that regard. Note: I…
Andrew Lauer Barinov
  • 5,694
  • 10
  • 59
  • 83
29
votes
2 answers

What's the difference between path and URL in iOS?

In a class such as NSFileManager there are 2 versions of practically every method. One for paths and one for URLs. What's the difference? And what's the best practice for converting a URL to a path.
Andrew
  • 8,363
  • 8
  • 43
  • 71
29
votes
10 answers

What characters are allowed in a iOS file name?

I'm looking for a way to make sure a string can be used as a file name under iOS. I'm currently in the section of the code that deletes incompatible characters. I'm wondering if I'm doing it right. NSString *filename = @"A file name"; fileName =…
Constantino Tsarouhas
  • 6,846
  • 6
  • 43
  • 54
1
2
3
96 97