mkdir(path[, mode=0777])

makedirs(name,mode=511)

rmdir(path)

removedirs(path)

listdir(path)

getcwd()

chdir(path)

walk(top, topdown=True, onerror=None)  返回一个元组:(遍历的路径,目录,文件列表)


我们来遍历一下文件:

 >>> for path, dir, filename in os.walk('/home/branches/python/testdir'):
... for filen in filename:
... os.path.join(path, filen)
...
'/home/branches/python/testdir/f1'
'/home/branches/python/testdir/f2'
'/home/branches/python/testdir/f3'
'/home/branches/python/testdir/jpg/0.ipg'
'/home/branches/python/testdir/jpg/3.ipg'
'/home/branches/python/testdir/jpg/2.ipg'
'/home/branches/python/testdir/jpg/1.ipg'
'/home/branches/python/testdir/jpg/get_img.py'
>>>
>>>
>>>
>>> for path, dir, filename in os.walk('testdir'):
... for filen in filename:
... os.path.join(path, filen)
...
'testdir/f1'
'testdir/f2'
'testdir/f3'
'testdir/jpg/0.ipg'
'testdir/jpg/3.ipg'
'testdir/jpg/2.ipg'
'testdir/jpg/1.ipg'
'testdir/jpg/get_img.py'
>>>
 #!/usr/bin/python
#coding:utf8 import os def dirList(path): # 列出当前目录下的完整路径名
filelist = os.listdir(path)
# fpath = os.getcwd() # 它获取的是程序所在路径
allfile = []
for filename in filelist:
# allfile.append(fpath + '/' + filename)
filepath = os.path.join(path, filename) # 用os模块的方法进行路径拼接
if os.path.isdir(filepath):
dirList(filepath)
print filepath allfile = dirList('/home/branches/python/testdir')

最新文章

  1. 你真的会用 SDWebImage?
  2. 某Python群的入群题目
  3. android 38 Abdroid客户端和服务端交互
  4. 哈哈,CSDN又支持Windows Live Writer了
  5. 解决SQL Server 占用80端口
  6. vector 对象中存放指针类型数据
  7. php使用openssl加密数据
  8. 打印中文dict list的各种姿势
  9. 2018.11.30开始学习shader
  10. 利用"SQL"语句自动生成序号的两种方式
  11. XML之Well-Formed文档规则
  12. java多线程快速入门(四)
  13. java BitSet2
  14. org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)错误几种解决方案
  15. PAT甲题题解-1005. Spell It Right (20)-数位求和,水
  16. CTreeCtrl获得鼠标点击时的节点
  17. 通过yum升级gcc/g++至版本4.8.2
  18. Guava Files 源码分析(二)
  19. Unit Test Generator 简介
  20. javascript 打印错误信息 catch err

热门文章

  1. C++中逗号操作符重载的分析
  2. undefined,null,!,!=之间的关系
  3. python-列表基本操作
  4. 页面跳转到Area区域连接
  5. js实现倒计时+div下落
  6. python实现发送文本邮件
  7. React 滚动事件
  8. Windows7有“系统保留”分区时,安装系统要注意的两点
  9. js正则去掉所有html标签/某一特定字符
  10. rabbitMQ初始化配置