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

yipeiwu_com5年前Python基础

来源: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使用socket 先读取长度,在读取报文内容示例

本文实例讲述了python使用socket 先读取长度,在读取报文内容。分享给大家供大家参考,具体如下: tlpmts1:~/sbin # cat test9105.py # -*-...

详解关于Django中ORM数据库迁移的配置

简介 ORM: 关系对象映射。定义一个类自动生成数据库的表结构。 创建数据库的时候,一般有以下几种常用数据类型:数字、字符串以及时间。 ORM分为两种: DB First...

django框架使用方法详解

django框架使用方法详解

我的文章的意义 服务端开发,python,django这些内容上面的链接中有详细的阐述. 我写的内容肯定没有上面的完备,准确. 我的文章的价值在于从一个iOS程序员的角度来理解服务端开...

对python tkinter窗口弹出置顶的方法详解

如果想要python 的tkinter窗口置顶,加上下面两句即可实现root窗口的置顶显示,可以用于某些程序的消息提示,能够弹出到桌面显示 root = Tk() root.wm_a...

python with提前退出遇到的坑与解决方案

问题的起源 早些时候使用with实现了一版全局进程锁,希望实现以下效果: with CacheLock("test_lock", 10): #如果抢占到锁,那么就执行这段代码...