#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2013
    Posts
    1
    Rep Power
    0

    Searching files in multiple folders in a directory


    Hello,

    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.

    thanks!
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Location
    /dev/null
    Posts
    163
    Rep Power
    19
    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.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2012
    Posts
    39
    Rep Power
    3
    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.

IMN logo majestic logo threadwatch logo seochat tools logo