首页 > 编程语言 > 详细

Python - Package os

时间:2016-02-11 17:57:18      阅读:346      评论:0      收藏:0      [点我收藏+]
for (path,dirs,files) in os.walk(path):
    for filename in files:
        #do something here

os. walk(top, topdown=True, onerror=None, followlinks=False)

  - Generate the file names in a directory tree by walking the tree either top-down or bottom-up. For each directory in the tree rooted at directory top (including top itself), it yields a 3-tuple (dirpath, dirnames, filenames).

 

for i in os.listdir(os.getcwd()):
    if(os.path.isfile(i)):
        #do something here

os.listdir(path)

   - Return a list containing the names of the entries in the directory given by path. The list is in arbitrary order. It does not include the special entries ‘.‘ and ‘..‘ even if they are present in the directory.

Python - Package os

原文:http://www.cnblogs.com/kiddy/p/5186545.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!