【发布时间】:2013-09-15 13:15:36
【问题描述】:
问题如题,方法如下:
def walkThroughPath(self , sBasePath, blFolders = True, blFiles = True ):
aPaths = []
for sRootDir, aSubFolders, aFiles in os.walk( sBasePath ):
for sFolder in aSubFolders:
if blFolders == True:
aPaths.append( sRootDir )
for sFileName in aFiles:
if blFiles == True:
aPaths.append( sRootDir + "/" + sFileName )
return aPaths
该方法返回大量子文件夹和文件,但肯定不是我找到的全部。
我的方法有什么问题(或者是 os.walk 的错误用法)?
对于那些对背景感兴趣的人:
http://www.playonlinux.com/en/topic-10962-centralized_wineprefix_as_preparation_for_debpackages.html
【问题讨论】:
-
如果你要使用匈牙利符号do it right。更好的是改善名称。复数表示集合,动词+名词表示布尔等。另外,您的第三个 for 循环是否缩进正确?
-
嗨史蒂文,你是对的。我什至不知道匈牙利符号。它只是我习惯用 PHP 编码的方式,我只是将它移植到 python,即使我知道 python 使用其他 labeks 作为他们的类型(当然还有其他的):-)。翻译:s=string,a=array,bl=boolean。很明显,这对于使用此类标准的人来说并不明显。希望代码无论如何都是可以理解的;-)
标签: python path subdirectory os.walk