title: Concatenating fasta files in folder into single file in python
body: <p>I have multiple fasta sequence files stored in a folder within my current working directory (called &quot;Sequences&quot;) and am trying to combine all the sequences into a single file to run a MUSLCE multiple sequence alignment on.</p>
  <p>This is what I have so far and it is functional up until the output_fas.close(), where i get the error message <strong>FileNotFoundError: [Errno 2] No such file or directory: './Sequences'</strong></p>
  <p>Here is the code:</p>
  <pre><code> import os
  os.getcwd() #current directory
  DIR = input(&quot;\nInput folder path containing FASTA files to combine into one FASTA file: &quot;)
  os.chdir(DIR)
  FILE_NAME = input(&quot;\nWhat would you like to name your output file (e.g. combo.fas)? Note: &quot;
                    &quot;Please add the .fas extension: &quot;)
  output_fas = open(FILE_NAME, 'w')
  file_count = 0
  
  for f in os.listdir(DIR):
      if f.endswith(( &quot;.fasta&quot;)):
          file_count += 1
          fh = open(os.path.join(DIR, f))
          for line in fh:
              output_fas.write(line)
          fh.close()
  
  output_fas.close()
  print(str(file_count) + &quot; FASTA files were merged into one file, which can be found here: &quot; + DIR)
  </code></pre>
  <p>When i input the directory i input it as './Sequences' which successfully changes the directory.</p>
  <p>Not quite sure what to do. I adjusted the code before and it successfully created the new files with all the sequences concatenated together, however it ran continuously and would not end and had multiple repeats of each sequence.</p>
  <p>Appreciate the help!</p>