views:

213

answers:

2

Hi friends,

I have a folder structure at server side. Inside the folders there are files of all format like .txt, .pdf. I get the structure in XML format.

Now I want to create the same folder structure that is present in server side at my iphone documents folder with only the names of files inside it and not the content of the files.

eg: folder1

    1.text(it is inside folder1)

folder2

    2.pdf(it is inside folder2)

folder3

   subFolder3 (it is inside folder3)
                          3.txt (it is inside subFolder3)

folder4

    4.txt

How I need to handle the overall approach.

Any help would be highly appreciated.

Waiting for your reply

+1  A: 
  1. To get the path to the documents directory, do this:

    NSString *documentsDirectory;
    NSArray *paths = NSSearchPathForDirectoriesInDomains
                    (NSDocumentDirectory, NSUserDomainMask, YES);
    if ([paths count] > 0)  {
        documentsDirectory = [paths objectAtIndex:0];
    }
    
  2. For each of your subdirectories and files you can use -[NSString stringByAppendingPathComponent:] to construct the path.

  3. To create each directory use -[NSFileManager createDirectoryAtPath:withIntermediateDirectories:attributes:error:].

  4. To create each file use -[NSFileManager createFileAtPath:contents:attributes:], passing [NSData data] as the contents to create an empty file.

cduhn
A: 

Thanks cduhn for your answer.

I hope I have not framed the question properly.

I have a server side and the device side(iPhone). At server side there is a folder structure where there can be files inside the folders as I have explained above.

I make the calls to server side and I get XML response as below (note i have inserted "." inside tags as it was not displaying in this site)‪

<.Response>‬

  <.item>‬<.path>/folder1<./path>‬ ‪<./item>‬

 <.item>‬<.path>/folder2<./path>‬<./item>‬

 <.item>‬<.path>/1.txt<./path>‬<./item>‬

‪<./Response>‬


I get the XML from server and the names of the files and folders are there in XML structure. Now when I receive the XML I only want to link the folders with the file name with the respective path(as of were this file is residing) and only save the file when the user chooses to save the file.

Basically simple browsing of the folder structure should be shown at iphone side and if user chooses to save any file then only I will save it otherwise he can only view the file.

Please know me your valuable inputs on how to approach this task.

Waiting for your reply.

Ekra