title: Loop through every file with specific format in a directory using sys argv
body: <p>I'd like to loop through every file in a directory given by the user and apply a specific transformation for every file that ends with &quot;.fastq&quot;.</p>
  <p>Basically this would be the pipeline:</p>
  <ol>
  <li>User puts the directory of where those files are (in command line)</li>
  <li>Script loops through every file that has the format &quot;.fastq&quot; and applies specific transformation</li>
  <li>Script saves new output in &quot;.fasta&quot; format</li>
  </ol>
  <p>This is what I have (python and biopython):</p>
  <pre><code>import sys, os
  from Bio import SeqIO
  from Bio.SeqIO.QualityIO import FastqGeneralIterator
  from pathlib import Path
  
  path = Path(sys.argv[1])
  print(path)
  
  glob_path = path.glob('*')
  
  for file_path in glob_path:
      if file_path.endswith(&quot;.fastq&quot;):
          with open(glob_path, &quot;rU&quot;) as input_fq:
              with open(&quot;{}.fasta&quot;.format(file_path),&quot;w&quot;) as output_fa:
                  for (title, sequence, quality) in FastqGeneralIterator(input_fq):
                      output_fa.write(&quot;&gt;%s\n%s\n&quot; \
                                      % (title, sequence))
  
  if not os.path.exists(path): 
      raise Exception(&quot;No file at %s.&quot; % path)
  
  </code></pre>
  <p>The script I have is running, but it is not producing the ouput (it is not creating the fasta file as desired). How could I make it so that the script loops through the files of a specific directory and passes the global path for each file onto the for loop so that the content of input_fq is read and a given transformation is saved onto the output_fa?</p>