To iterate through all the files within the specified directory (folder), with ability to use wildcards (*, ?, and [ ]-style ranges), use the following code snippet:
PYTHON:
- import os
- import glob
- path = 'sequences/'
- for infile in glob.glob( os.path.join(path, '*.fasta') ):
- print "current file is: " + infile
If you do not need wildcards, then there is a simpler way to list all items in a directory:
PYTHON:
- import os
- path = 'sequences/'
- listing = os.listdir(path)
- for infile in listing:
- print "current file is: " + infile
No comments:
Post a Comment