Wednesday, 25 September 2013

Filter File based on directory

Filter File based on directory

I have directory which contain multiple sub directory and each sub
directory also contain multiple directory.I have file which present in all
sub directory and need to pick file based on sub directory.Can I get some
input.
like <cell 1> <cell 2> <cell 3>
each cell1
<job 1> <job 2> < job 3>
each job contain sample. txt
similar cell2 and cell 3. So I want to extract sample.txt from each
cell/job1 directory. and written following program. just modify program
after fix issue . Can we done more better way
#!/usr/bin/py
import os
def find_all(name, path):
result = []
for root, dir, files in os.walk(path):
print "root %s dir %s" %(root, dir)
if "job1" in root:
print "\n"
if name in files:
result.append(os.path.join(root, name))
return result
name = "sample.txt"
path = "."
data = find_all(name, path)
print data
~

No comments:

Post a Comment