June 10th, 2013, 01:57 AM
Searching files in multiple folders in a directory
I want to write a program that upon receipt of a query, searches multiple folders in a directory, reads the files in the folders and produces the required results.
Any tips or hints as to how to do this in python? I'm not asking for code. I'm using this project to become proficient at python. I am kindly requesting for assistance as to how to go about this.
June 10th, 2013, 02:19 AM
Iterate over the contents of the directory.
If the current element is a file, do what you have to with a file.
If the current element is a directory, go into the directory and repeat the above steps.
You may have to write a recursive function that will call itself if the current element is a directory.
June 10th, 2013, 10:46 AM
For the search look at os.walk to see it that helps. You may also find regular expressions (the re module) useful depending upon what you are doing with the files.