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

相关文章

python3中str(字符串)的使用教程

本文主要介绍的是python3中对str(字符串)的使用操作总结,文中介绍的非常详细,需要的朋友们下面来一起看看吧。 __add__函数 (在后面追加字符串) s1 ='Hello'...

python3之模块psutil系统性能信息使用

psutil是个跨平台库,能够轻松实现获取系统运行的进程和系统利用率,包括CPU、内存、磁盘、网络等信息。 它主要应用于信息监控,分析和限制系统资源及进程的管理。它实现了同等命令命令行工...

python操作日期和时间的方法

不管何时何地,只要我们编程时遇到了跟时间有关的问题,都要想到 datetime 和 time 标准库模块,今天我们就用它内部的方法,详解python操作日期和时间的方法。1.将字符串的时...

利用python提取wav文件的mfcc方法

如下所示: import scipy.io.wavfile as wav from python_speech_features import mfcc fs, audio = wa...

python消除序列的重复值并保持顺序不变的实例

python 消除序列的重复值,并保持原来顺序 1、如果仅仅消除重复元素,可以简单的构造一个集合 $ python Python 3.5.2 (default, Nov 23 201...