views:

299

answers:

1

Hi, I'm new in Iphone programing, I need code to:

  • check if a specific target subfolder exist in the document folder ?
  • if target subfolder exist in document folder, I want to delete target subfolder
  • if target subfolder does not exist in document folder, I want to create target subfolder in document folder

Thank's in advance for your help !

+3  A: 

You need to use NSFileManager class functionality.
To get Documents directory path:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *documentsDirectory = [paths objectAtIndex:0];  // Get Documents directory

To check if directory (or file) exists at given path:

- (BOOL)fileExistsAtPath:(NSString *)path
- (BOOL)fileExistsAtPath:(NSString *)path isDirectory:(BOOL *)isDirectory

Remove item at path:

- (BOOL)removeItemAtPath:(NSString *)path error:(NSError **)error

Create directory at path:

- (BOOL)createDirectoryAtPath:(NSString *)path attributes:(NSDictionary *)attributes

For more details on these functions see NSFileManager class reference.

Vladimir
Thank's for your help !GPSDEV