Created
March 18, 2019 10:41
-
-
Save caoya171193579/a591436e4190af3107e0c4e929130be0 to your computer and use it in GitHub Desktop.
进阶
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-递归函数 | |
os.walk() 函数 | |
笨办法 | |
################################## | |
1、遍历一个指定的目录wenjiancaozuo | |
path[帕斯]:路径 | |
append() 方法用于在列表末尾添加新的对象。 | |
 | |
知识点: | |
os模块下path.join参数将返回的目录和文件名合成一个路径 | |
运行结果: | |
 | |
2、当我们遍历的目录下还有一个dirr目录如何接着遍历此目录下的文件。 | |
知识点: | |
os模块下path.isdir参数判断路径是否为目录。 | |
然后代码的位置一定要放好,不然执行很容易出错。 | |
 | |
运行结果: | |
 | |
######################################## | |
用os.walk() 遍历目录 | |
-os.walk(path) | |
 | |
该函数返回一个元祖,该元祖有3个元素,这3个元素分别表示每次遍历的路径名,目录列表和文件列表。 | |
返回的元祖对象,用next()函数返回元祖。 | |
 | |
3、删除目录内的文件 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment