python
os模块
os
import os
def GetFileList(dir, fileList):
newDir = dir
if os.path.isfile(dir):
fileList.append(dir.encode('gbk'))
elif os.path.isdir(dir):
for s in os.listdir(dir):
#如果需要忽略某些文件夹,使用以下代码
#if s == "xxx":
#continue
newDir=os.path.join(dir,s)
GetFileList(newDir, fileList)
return fileList
list = GetFileList('C:pyqt4/', [])
for e in list:
print (e)
该文章介绍了一个使用Python的os模块遍历文件系统的函数GetFileList,它递归地访问目录并将文件路径添加到列表中。在处理过程中,对文件路径进行了GBK编码,并且可以忽略特定文件夹。示例展示了如何从C:/pyqt4/路径开始获取文件列表。
1630

被折叠的 条评论
为什么被折叠?



