問題自体だけでなく、質問を説明しようとしても問題があります。約 7 回の繰り返しで構成されるディレクトリ ツリーがあるので、次のようにします。rootdir/a/b/c/d/e/f/destinationdir
次のように、5 つのサブディレクトリ レベルを持つものもあれば、10 ものサブディレクトリ レベルを持つものもあります。
rootdir/a/b/c/d/destinationdir
また:
rootdir/a/b/c/d/e/f/g/h/destinationdir
唯一の共通点は、宛先ディレクトリの名前が常に同じであることです。glob 関数を使用する方法は次のとおりです。
for path in glob.glob('/rootdir/*/*/*/*/*/*/destinationdir'):
--- os.system('cd {0}; do whatever'.format(path))
ただし、これは正確な数の中間サブディレクトリを持つディレクトリに対してのみ機能します。その数を指定する必要がない方法はありますかsubdirectories(asterices)
; 言い換えれば、中間サブディレクトリの数に関係なく関数をdestinationdirに到達させ、それらを反復処理できるようにします。どうもありがとう!