Created
April 12, 2013 19:55
-
-
Save bobhancockgist/5374660 to your computer and use it in GitHub Desktop.
Python: files in dir
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import sys | |
def main(): | |
if len(sys.argv) < 2: | |
sys.stderr.write("usage: scriptname source_dir") | |
sys.exit(1) | |
source_dir = sys.argv[1] | |
try: | |
files = os.listdir(source_dir) | |
except OSError as e: | |
sys.stderr.write("Cannot retrieve file names: "+str(e)) | |
sys.exti(1) | |
for f in files: | |
fname = os.path.join(source_dir, f) | |
with open(fname, "r") as fh: | |
pass # this is where you do stuff | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment