title: Python: Loop to open multiple folders and files in python
body: <p>I am new to python and currently work on data analysis.</p>
  
  <p>I am trying to open multiple folders in a loop and read all files in folders.
  Ex. working directory contains 10 folders needed to open and each folder contains 10 files. </p>
  
  <p>My code for open each folder with .txt file;</p>
  
  <pre><code>file_open = glob.glob("home/....../folder1/*.txt")
  </code></pre>
  
  <p>I want to open folder 1 and read all files, then go to folder 2 and read all files... until folder 10 and read all files. 
  Can anyone help me how to write loop to open folder, included library needed to be used? </p>
  
  <p>I have my background in R, for example, in R I could write loop to open folders and files use code below.</p>
  
  <pre><code>folder_open &lt;- dir("......./main/")
  for (n in 1 to length of (folder_open)){
      file_open &lt;-dir(paste0("......./main/",folder_open[n]))
  
      for (k in 1 to length of (file_open){
          file_open&lt;-readLines(paste0("...../main/",folder_open[n],"/",file_open[k]))
          //Finally I can read all folders and files.
      }
  }
  </code></pre>