listdir()方法返回一个包含由路径给出的目录条目名称的列表。该列表在任意顺序。它不包括特殊项目“.”和“..”,即使它们存在在目录中。
	
路径可以是任一类型 str 或 类型字节。如果路径是类型字节,返回的文件名也将是类型字节; 在所有其他情况下,它们是类型str。
语法
		以下是 listdir() 方法的语法:
	
os.listdir(path)
参数
- 
			path -- 这是待探索的目录 
		
			返回值
		
	
	
		这个方法返回一个包含由路径给出的目录条目名称的列表。
	
	示例
		下面的示例显示 listdir()方法的使用。
	
#!/usr/bin/python3 import os, sys # Open a file path = "d:\\tmp\\" dirs = os.listdir( path ) # This would print all the files and directories for file in dirs: print (file)
		当我们运行上面的程序,它会产生以下结果:
	
Applicationdocs.docx test.java book.zip foo.txt Java Multiple Inheritance.html Java Multiple Inheritance_files java.ppt ParallelPortViewer
						上一篇:
								Python3文件方法
												下一篇:
								Python3 os文件目录的方法
												
						
						
					
					
					