在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.

相关文章

Django中对数据查询结果进行排序的方法

在你的 Django 应用中,你或许希望根据某字段的值对检索结果排序,比如说,按字母顺序。 那么,使用 order_by() 这个方法就可以搞定了。 >>> Pub...

python交互式图形编程实例(二)

本文实例为大家分享了python交互式图形编程的第二部分代码,供大家参考,具体内容如下 #!/usr/bin/env python3 # -*- coding: utf-8 -*-...

探究Python多进程编程下线程之间变量的共享问题

 1、问题: 群中有同学贴了如下一段代码,问为何 list 最后打印的是空值?   from multiprocessing import Process, M...

django+echart数据动态显示的例子

目标:从plc采集数据到数据库,利用echart绘制实时动态曲线。 1 思路 - django定时执行任务,将数据推送到echart。 - 前端定时读取后端数据,并显示到echart上。...

python条件变量之生产者与消费者操作实例分析

python条件变量之生产者与消费者操作实例分析

本文实例讲述了python条件变量之生产者与消费者操作。分享给大家供大家参考,具体如下: 互斥锁是最简单的线程同步机制,面对复杂线程同步问题,Python还提供了Condition对象。...