0

I need to traverse all the files in the folder structure of the directory accessed by the app from shared servers. With the inclusion static libraries I'm able to access various servers and the files shared in the them. List of all servers are stored in NSArray

I need to traverse through all folders shared by server to store all files in a container. I have used recursion but that has huge impact on the performance in case number of folders and sub folders increase.

Can anyone suggest any algorithm or logic to traverse the directory structure.

Kindly refer below illustration to have an idea of structure.

enter image description here

One of the possibility could be usage of threads but how to divide the logic to iterate all folders for files so that threads can work on them parallel.

Being a mobile app I don't have a luxury of memory.

DNamto
  • 1,342
  • 1
  • 21
  • 42

1 Answers1

0

Remark: "I don't have a luxury of memory." - ask an engineer who worked in the 70's. He will say that the 1GB of RAM you have in your iPhone is more than enough.

To the point: are you sure that it is indeed the recursion itself that has such a great impact on performance? Of course, there are algorithms for traversing a tree data structure (such as a directory in the filesystem) without recursion, using an explicit stack, but that really is painful.

Instead, make sure you obtain only the necessary information, so do not, for example, get all the attributes and hard link count and birthday and... and... of a file if all you need is its full path.