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

作者:mdxy-dxy 时间:2022-08-04 20:48:47 

来源: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.

标签:移动目录结构
0
投稿

猜你喜欢

  • 在PHP中读取和写入WORD文档的代码

    2023-09-28 02:30:22
  • SQL Server中的集合运算: UNION, EXCEPT和INTERSECT示例代码详解

    2024-01-28 14:49:33
  • python list格式数据excel导出方法

    2023-09-19 14:21:01
  • python删除文件夹中具有相同后缀类型文件的实战演练

    2022-04-18 19:47:29
  • python网络编程 使用UDP、TCP协议收发信息详解

    2021-02-15 14:37:41
  • 利用Java正则表达式校验邮箱与手机号

    2023-07-03 15:14:54
  • python实现的一个火车票转让信息采集器

    2023-09-05 11:42:53
  • 一文搞懂python异常处理、模块与包

    2023-09-05 05:01:25
  • 详解如何将python3.6软件的py文件打包成exe程序

    2022-09-26 00:10:21
  • JS弹出窗口插件zDialog简单用法示例

    2024-05-22 10:32:18
  • SQL Server数据库优化经验总结

    2009-03-16 14:22:00
  • Vscode ChatGPT插件使用(无需代理注册)

    2023-05-13 18:25:01
  • Django学习笔记之View操作指南

    2023-05-29 14:08:47
  • Python编程快速上手——疯狂填词程序实现方法分析

    2023-07-25 08:57:17
  • 使用python Telnet远程登录执行程序的方法

    2022-12-22 11:56:57
  • asp函数解决SQL注入漏洞

    2008-10-12 19:53:00
  • Golang交叉编译(跨平台编译)的使用

    2024-05-02 16:26:40
  • Python实现特定场景去除高光算法详解

    2021-11-16 09:50:03
  • 利用WSH获取计算机硬件信息、DNS信息等

    2008-05-05 13:04:00
  • python库pydantic的简易入门教程

    2022-06-27 14:05:28
  • asp之家 网络编程 m.aspxhome.com