私は、ディレクトリ内のrepository.configファイルの最初の表示を取得し、サブディレクトリの検索を停止する必要があります。os.walk最初に見つかった後にサブディレクトリを探すのをやめてください
./WAS80/base/disk1/ad/repository.config ./WAS80/base/disk1/md/repository.config ./WAS80/base/disk2/ad/repository.config ./WAS80/base/disk3/ad/repository.config ./WAS80/base/disk4/ad/repository.config ./WAS80/base/repository.config ./WAS80/fixpack/fp5/repository.config ./WAS80/fixpack_suplements/fp5/repository.config ./WAS80/supplements/disk1/ad/repository.config ./WAS80/supplements/disk1/md/repository.config ./WAS80/supplements/disk2/ad/repository.config ./WAS80/supplements/disk3/ad/repository.config ./WAS80/supplements/disk4/ad/repository.config ./WAS80/supplements/repository.config
私は太字のものを必要とし、サブディレクトリに探して停止します。
は、ここに私のディレクトリツリーです。
私はこのコードを試し始めましたが、わかりませんでした。
pattern='repository.config'
path='/opt/was_binaries'
def find_all(name, path):
result = []
for root, dirs, files in os.walk(path):
if name in files:
result.append(os.path.join(root, name))
continue
return result
適切にあなたのコード一つのインデントのために。 Pythonはスペースに非常に敏感です。別のものについては、 "基本的に"あなたの段落を開始しないでください。 –
「私はこのコードを試し始めましたが、わかりませんでした」平均?あなたが気に入らない、または理解していないことは何をしていますか?具体的にしてください。コメントに返信しないでください!あなたの質問を編集して、独立した問題の声明にしてください。 –