0

I am trying to loop through a directory and filename into a variable to be manipulated.

Example:

Dir contains:

stuff.txt home.txt ... specs.txt

for loop:
     var = [filenames in the dir such as stuff,home,spec..]
     print hash(var)

Would it be possible to include sub directories?

Doyle
  • 3
  • 2

1 Answers1

0

You could start with something like this using os.listdir:

import os
your_dir = '/home/...' # Dir path

for filename in os.listdir(your_dir):
    if os.path.isfile(filename):
        print filename
        do_something(filename)

With do_something being you hash function and so on.

d6bels
  • 1,432
  • 2
  • 18
  • 30