在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射线法判断点是否位于区域内的具体代码,供大家参考,具体内容如下 #!/usr/bin/env python # -*- coding: utf-8 -...

python实现单向链表详解

python实现单向链表详解

本文研究的主要是Python中实现单向链表的相关内容,具体如下。 什么是链表 链表顾名思义就是~链 链表是一种动态数据结构,他的特点是用一组任意的存储单元存放数据元素。链表中每一个元...

python 多进程通信模块的简单实现

多进程通信方法好多,不一而数。刚才试python封装好嘅多进程通信模块 multiprocessing.connection。 简单测试咗一下,效率还可以,应该系对socket封装,效率...

python 检查数据中是否有缺失值,删除缺失值的方式

# 检查数据中是否有缺失值 np.isnan(train).any() Flase:表示对应特征的特征值中无缺失值 True:表示有缺失值 通常情况下删除行,使用参数axis =...

使用Python对Excel进行读写操作

学习Python的过程中,我们会遇到Excel的读写问题。这时,我们可以使用xlwt模块将数据写入Excel表格中,使用xlrd模块从Excel中读取数据。下面我们介绍如何实现使用Pyt...