在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 FTP批量下载/删除/上传实例

python FTP批量下载/删除/上传实例

最近几天,学习python3的对FTP操作,做下总结!!!! 1.FTP链接 这样写的好处就是如果报错,很快就能找到错在哪里,方便找到问题。 2.FTP文件批量下载 有点要注意的:...

djano一对一、多对多、分页实例代码

昨日内容: ORM高级查询 -filter id=3 id__gt=3 id__lt=3 id__lte=3 id__gte=3 -in /not in .filter(id__i...

python读取并定位excel数据坐标系详解

python读取并定位excel数据坐标系详解

测试数据:坐标数据:testExcelData.xlsx 使用python读取excel文件需要安装xlrd库: xlrd下载后的压缩文件:xlrd-1.2.0.tar.gz 解压后再...

windows系统下Python环境的搭建(Aptana Studio)

windows系统下Python环境的搭建(Aptana Studio)

1、首先访问http://www.python.org/download/去下载最新的python版本。 2、安装下载包,一路next。 3、为计算机添加安装目录搭到环境变量,如图...

Python多继承顺序实例分析

本文实例讲述了Python多继承顺序。分享给大家供大家参考,具体如下: 示例1: #-*- coding:utf-8 -*- #!python2 class A(object):...