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

相关文章

numpy ndarray 取出满足特定条件的某些行实例

在进行物体检测的ground truth boxes annotations包围框坐标数据整理时,需要实现这样的功能: numpy里面,对于N*4的数组,要实现对于每一行,如果第3列和第...

Python 对象中的数据类型

对于python,一切事物都是对象,程序中存储的所有数据都是对象,对象基于类创建 计算机能处理的远不止数值,还可以处理文本、图形、音频、视频、网页等各种各样的数据,不同的数据,需要定义不...

Django使用模板后无法找到静态资源文件问题解决

环境配置 Django版本1.11 python版本3.6.2 前言 在编写Django网站的时候,在涉及模板方面,一些简单的例子都没有问题,但这些例子都有一个共同点,那...

Python中Selenium模拟JQuery滑动解锁实例

Python中Selenium模拟JQuery滑动解锁实例

本文介绍了Python中Selenium模拟JQuery滑动解锁实例,分享给大家,也给自己留个笔记 滑动解锁一直做UI自动化的难点之一,我补一篇滑动解锁的例子,希望能给初做Web UI自...

pygame实现俄罗斯方块游戏(AI篇2)

pygame实现俄罗斯方块游戏(AI篇2)

继续pygame实现俄罗斯方块游戏(AI篇1)的代码更新 一、消除后才做评价 上一篇我们是对方块落下的位置和落下后出来的空洞进行了评价,但是这些评价都是没有计算消除的,以至于机器人现在不...