i have about 500 folder and each folder has 2 text files.I need to insert all those files in database.Right now my program has to read each and every folder, is there any other alternative to this.
Your problem looks like the classic trick question: "What is the time complexity of printing a binary search tree?". It is a trick question because "everyone knows" that binary search trees are have logarithmic complexity, but to print all of the nodes in the tree, the algorithm still has to visit all of the nodes. So the complexity is linear.
Likewise, if you need to insert all files into the data base and the files are spread across 500 folders, you still need to check every folder. The best you can get is a linear traversal of the folders.