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

yipeiwu_com6年前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基础之函数原理与应用实例详解

本文实例讲述了Python基础之函数原理与应用。分享给大家供大家参考,具体如下: 目标 函数的快速体验 函数的基本使用 函数的参数 函数的返回值 函数的嵌套调用...

TensorFlow中权重的随机初始化的方法

一开始没看懂stddev是什么参数,找了一下,在tensorflow/python/ops里有random_ops,其中是这么写的: def random_normal(shape,...

详解python的sorted函数对字典按key排序和按value排序

详解python的sorted函数对字典按key排序和按value排序

1.sorted函数按key值对字典排序 先来基本介绍一下sorted函数,sorted(iterable,key,reverse),sorted一共有iterable,key,reve...

简单介绍Python的轻便web框架Bottle

基本映射 映射使用在根据不同URLs请求来产生相对应的返回内容.Bottle使用route() 修饰器来实现映射. from bottle import route, run@rou...

详解python做UI界面的方法

详解python做UI界面的方法

一直以来都是用python脚本,执行的时候就是在终端直接命令执行,或者直接输入代码执行,最近为了方便他人使用,想做个界面,可以通过里面的控件菜单直接点击执行程序功能。 在文件夹中创建一...