複数のサブディレクトリを含むディレクトリがあり、各サブディレクトリにも複数のディレクトリが含まれています.すべてのサブディレクトリに存在するファイルがあり、サブディレクトリに基づいてファイルを選択する必要があります.入力を取得できますか.
like <cell 1> <cell 2> <cell 3>
each cell1
<job 1> <job 2> < job 3>
each job contain sample. txt
cell2 と cell 3 も同様です。したがって、各 cell/job1 ディレクトリから sample.txt を抽出します。そして以下のプログラムを書きました。 問題を修正した後にプログラムを変更するだけです。より良い方法を行うことができますか
#!/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
〜