How to Create multiple subfolders inside the document folder

Discussion in 'iOS Programming' started by sanjeev, Mar 1, 2010.

  1. sanjeev macrumors newbie

    Joined:
    Dec 18, 2009
    #1
    Hello Friends,

    I have an issue.

    In my app., I want to cache the images coming from server into local document directory. For that I need to create sub-folders each containing particular set of images.

    I have created one sub-folder directly inside the document directory like:

    /documents/subfolder1

    Now, when I try to create another subfolder, it gets overwriting the first folder :( . I have been stucked here for last 2 days and I really want to complete it anyhow by the end of the day.

    If anyone has any idea about this, please help me.

    Prompt response will be highly appreciated.

    Thanks,
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    1) Post your code

    2) Just create the second folder with a different name?
     
  3. sanjeev thread starter macrumors newbie

    Joined:
    Dec 18, 2009
    #3
    Thanks Man,

    I have implemented that succesfully.

    Code:
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *string1= [[paths objectAtIndex:0] stringByAppendingPathComponent:@"Titles"];
    
       NSString *string2= [[paths objectAtIndex:0] stringByAppendingPathComponent:@"EachBook"];
    
    /* check for existence of cache directory */
    	if ([[NSFileManager defaultManager] fileExistsAtPath:string1 ]) 
    	{
    		return;
    	}
    	
    	/* create a new cache directory */
    	if (![[NSFileManager defaultManager] createDirectoryAtPath:string1					   withIntermediateDirectories:YES attributes:nil error:&error]) 
    	{
    		URLCacheAlertWithError(error);
    		return;
    	}
    
          if ([[NSFileManager defaultManager] fileExistsAtPath:string2]) 
         {			
              return;
         }
     
     
        if (![[NSFileManager defaultManager] createDirectoryAtPath:string2													             withIntermediateDirectories:NO attributes:nil error:&error]) 
       {
    	URLCacheAlertWithError(error);
    			return;
       }
    Cheers,
     

Share This Page