Python os.listdir() 方法
Python 教程
· 2019-02-03 23:43:00
概述
os.listdir() 方法用于返回指定的文件夹包含的文件或文件夹的名字的列表。这个列表以字母顺序。 它不包括 '.' 和'..' 即使它在文件夹中。
只支持在 Unix, Windows 下使用。
语法
listdir()方法语法格式如下:
os.listdir(path)
参数
path -- 需要列出的目录路径
返回值
返回指定路径下的文件和文件夹列表。
实例
以下实例演示了 listdir() 方法的使用:
#!/usr/bin/python # -*- coding: UTF-8 -*- import os, sys # 打开文件 path = "/var/www/html/" dirs = os.listdir( path ) # 输出所有文件和文件夹 for file in dirs: print file
执行以上程序输出结果为:
test.htm stamp faq.htm _vti_txt robots.txt itemlisting resumelisting writing_effective_resume.htm advertisebusiness.htm papers resume
点击查看所有 Python 教程 文章: https://codercto.com/courses/l/8.html
Tales from Facebook
Daniel Miller / Polity Press / 2011-4-1 / GBP 55.00
Facebook is now used by nearly 500 million people throughout the world, many of whom spend several hours a day on this site. Once the preserve of youth, the largest increase in usage today is amongst ......一起来看看 《Tales from Facebook》 这本书的介绍吧!