好吧,我不僅在問題本身遇到問題,而且即使試圖解釋我的問題。我有一個目錄樹由大約7次迭代,所以:rootdir/a/b/c/d/e/f/destinationdir
Python Glob.glob:根和目標之間的目錄數量的通配符
的事情是有的可有5倍子目錄的水平,有些可能有多達十個,如:
rootdir/a/b/c/d/destinationdir
或:
rootdir/a/b/c/d/e/f/g/h/destinationdir
它們唯一共同的地方是目標目錄總是被命名爲相同的東西。我使用的水珠功能的方法如下:
for path in glob.glob('/rootdir/*/*/*/*/*/*/destinationdir'):
--- os.system('cd {0}; do whatever'.format(path))
然而,這僅適用於具備中級子目錄是精確數量的目錄。有什麼辦法可以讓我不必指定那個數字subdirectories(asterices)
;換句話說,無論中間子目錄的數量是多少,函數都會到達destinationdir,並允許我遍歷它們。非常感謝!