title: How can I save the content of all txt.files out of a folder and store them in a list?
body: <p>I need your help, please!
  I'm not a programmer, but I need this stuff for my thesis.</p>
  <p>My problem is: I have a lot of .txt-documents all saved in a folder:</p>
  <pre><code>folder_path = &quot;path/to/folder&quot;
  listOfFiles = os.listdir(folder_path)
  data = glob.glob(os.path.join(folder_path, '*.txt'))
  allLines = []
  </code></pre>
  <p>I already stored my filenames in a list and joined folder_path with the path of each file. And created an empty list, where the content of the files should be saved in the end.</p>
  <p>What I want to do:</p>
  <pre><code>for files in data:
          with codecs.open(files, 'r','utf-8-sig') as f: 
             text_ = f.read()
             allLines.append(text_.strip())
             print (text_) 
             print (len(text_))
             continue
  </code></pre>
  <p>Open each file out of the filelist in data, read it and save content in the new list. When I try to do it with the code below, it only saves the content of the first file in the folder. I understand that the problem is, that I can only define the name &quot;text_&quot; once, and that's the reason it doesn't work. But I read a lot of articles everywhere and can't find a solution for my problem.</p>
  <p>Hope someone can help me. Thank you very much!</p>
  <p>Edit: I need this Code from R in Python language:</p>
  <pre><code>folder&lt;-&quot;E:/Amadeus für MA/probe&quot;
  file_list&lt;- list.files(path=folder, pattern=&quot;*.txt&quot;)
  for (i in 1:length(file_list)){
    assign(file_list[i],
           read.table(paste(folder,file_list[i], sep='/'),fill = TRUE,sep = &quot;#&quot;,fileEncoding = &quot;UTF-8&quot;)
    )}
  </code></pre>