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

相关文章

tensorflow学习笔记之简单的神经网络训练和测试

tensorflow学习笔记之简单的神经网络训练和测试

本文实例为大家分享了用简单的神经网络来训练和测试的具体代码,供大家参考,具体内容如下 刚开始学习tf时,我们从简单的地方开始。卷积神经网络(CNN)是由简单的神经网络(NN)发展而来的,...

Python实现的调用C语言函数功能简单实例

Python实现的调用C语言函数功能简单实例

本文实例讲述了Python实现的调用C语言函数功能。分享给大家供大家参考,具体如下: 实例参考python cookbook 中的15.1节中的例子P612页 先把 c文件编译成 so文...

python处理文本文件并生成指定格式的文件

import os import sys import string #以指定模式打开指定文件,获取文件句柄 def getFileIns(filePath,model)...

使用Python下载Bing图片(代码)

直接上代码:复制代码 代码如下:<span style="font-family: arial,helvetica,sans-serif; font-size: 16px;">...

python使用multiprocessing模块实现带回调函数的异步调用方法

本文实例讲述了python使用multiprocessing模块实现带回调函数的异步调用方法。分享给大家供大家参考。具体分析如下: multipressing模块是python 2.6版...