在Python中移动目录结构的方法


Posted in Python onJanuary 31, 2016

来源:http://stackoverflow.com/questions/3806562/ways-to-move-up-and-down-the-dir-structure-in-python

#Moving up/down dir structure
print os.listdir('.') # current level
print os.listdir('..') # one level up
print os.listdir('../..') # two levels up
 
# more complex example:
# This will walk the file system beginning in the directory the script is run from. It 
# deletes the empty directories at each level
 
for root, dirs, files in os.walk(os.getcwd()):
  for name in dirs:
    try:
      os.rmdir(os.path.join(root, name))
    except WindowsError:
      print 'Skipping', os.path.join(root, name)

This will walk the file system beginning in the directory the script is run from. It deletes the empty directories at each level.

Python 相关文章推荐
python使用arp欺骗伪造网关的方法
Apr 24 Python
使用rpclib进行Python网络编程时的注释问题
May 06 Python
qpython3 读取安卓lastpass Cookies
Jun 19 Python
python爬虫实现教程转换成 PDF 电子书
Feb 19 Python
python实现FTP服务器服务的方法
Apr 11 Python
python在每个字符后添加空格的实例
May 07 Python
对python指数、幂数拟合curve_fit详解
Dec 29 Python
django模板加载静态文件的方法步骤
Mar 01 Python
详解python列表生成式和列表生成式器区别
Mar 27 Python
Python3.7+tkinter实现查询界面功能
Dec 24 Python
解决TensorFlow调用Keras库函数存在的问题
Jul 06 Python
python Polars库的使用简介
Apr 21 Python
python嵌套函数使用外部函数变量的方法(Python2和Python3)
Jan 31 #Python
python 爬取微信文章
Jan 30 #Python
python生成验证码图片代码分享
Jan 28 #Python
详解Python网络爬虫功能的基本写法
Jan 28 #Python
Python3实现Web网页图片下载
Jan 28 #Python
Python正则获取、过滤或者替换HTML标签的方法
Jan 28 #Python
Python每天必学之bytes字节
Jan 28 #Python
You might like
配置PHP使之能同时支持GIF和JPEG
2006/10/09 PHP
php中文字符截取防乱码
2008/03/28 PHP
Look And Say 序列php实现代码
2011/05/22 PHP
关于php curl获取301或302转向的网址问题的解决方法
2011/06/02 PHP
php/js获取客户端mac地址的实现代码
2013/07/08 PHP
微信随机生成红包金额算法php版
2016/07/21 PHP
使用PHPWord生成word文档的方法详解
2019/06/06 PHP
JAVASCRIPT车架号识别/验证函数代码 汽车车架号验证程序
2012/01/08 Javascript
JavaScript设计模式开发中组合模式的使用教程
2016/05/18 Javascript
bootstrap laydate日期组件使用详解
2017/01/04 Javascript
js取小数点后两位四种方法
2019/01/18 Javascript
在小程序中推送模板消息的实现方法
2019/07/22 Javascript
JS数组splice操作实例分析
2019/10/12 Javascript
vue el-upload上传文件的示例代码
2020/12/21 Vue.js
[00:09]DOTA2新版本PA至宝特效动作展示
2014/11/19 DOTA
python抓取某汽车网数据解析html存入excel示例
2013/12/04 Python
Python中的字符串类型基本知识学习教程
2016/02/04 Python
python2.x实现人民币转大写人民币
2018/06/20 Python
Python迭代器与生成器基本用法分析
2018/07/26 Python
python找出完数的方法
2018/11/12 Python
Python实现带参数的用户验证功能装饰器示例
2018/12/14 Python
python定时按日期备份MySQL数据并压缩
2019/04/19 Python
python可视化实现KNN算法
2019/10/16 Python
python实现身份证实名认证的方法实例
2019/11/08 Python
Python写出新冠状病毒确诊人数地图的方法
2020/02/12 Python
python中的unittest框架实例详解
2021/02/05 Python
基于 HTML5 的 WebGL 3D 版俄罗斯方块的示例代码
2018/05/28 HTML / CSS
顶岗实习接收函
2014/01/09 职场文书
管理专员自荐信
2014/01/26 职场文书
2014年向国旗敬礼活动总结
2014/09/27 职场文书
先进典型事迹材料
2014/12/29 职场文书
公务员个人年终总结
2015/02/12 职场文书
学校实习推荐信
2015/03/27 职场文书
初二英语教学反思
2016/02/15 职场文书
python批量创建变量并赋值操作
2021/06/03 Python
Python爬虫基础之初次使用scrapy爬虫实例
2021/06/26 Python