在Python中移动目录结构的方法
2016-01-31 00:00
856 查看
来源:http://stackoverflow.com/questions/3806562/ways-to-move-up-and-down-the-dir-structure-in-python
This will walk the file system beginning in the directory the script is run from. It deletes the empty directories at each level.
#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在不同层级目录import模块的方法
- Calibre 制作电子书
- python微博爬虫编写
- python爬虫基础登----网站登录
- Python黑帽子--黑客与渗透测试编程之道
- IPython4_Notebook
- python study note
- python利用有道翻译实现“语言翻译器”的功能
- Traits-为Python添加类型定义
- python学习之9 日志记录logging
- python请求服务器图片并下载到本地磁盘
- 《笨办法学Python》 第28课手记
- python weibo sdk开发
- [Python] 文件的读取、创建、追加、删除、清空
- LeetCode刷题 (Python) | 125. Valid Palindrome
- python中global 和 nonlocal 的作用域
- 笔试题-搜狐手机网Python开发工程师
- python资源整理
- 编写高质量代码--改善python程序的建议(八)
- Python 8.5 分布式进程