在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实现雨滴下落到地面效果

本文实例为大家分享了python实现雨滴下落到地面效果的具体代码,供大家参考,具体内容如下 本程序在Windows 64位操作系统下,安装的是Anaconda3-4.2.0 impo...

pthon贪吃蛇游戏详细代码

pthon贪吃蛇游戏详细代码

本文实例为大家分享了pthon贪吃蛇游戏的具体代码,供大家参考,具体内容如下 在写Python游戏项目时,最重要的时python中的pygame库。安装pygame库和用法在我CSDN...

对Pytorch中Tensor的各种池化操作解析

AdaptiveAvgPool1d(N) 对一个C*H*W的三维输入Tensor, 池化输出为C*H*N, 即按照H轴逐行对W轴平均池化 >>> a = torch...

Django 自定义分页器的实现代码

Django 自定义分页器的实现代码

为什么要实现分页? 在大部分网站中分页的功能都是必要的,尤其是在后台管理中分页更是不可或缺 分页能带给用户更好的体验,也能减轻服务器的压力 对于分页来说,有许多方法都可以实现 例如把数据...

python实现代码统计程序

本文实例为大家分享了python实现代码统计程序的具体代码,供大家参考,具体内容如下 # encoding="utf-8" """ 统计代码行数 """ import sys i...