在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 Django里CSRF 对应策略详解

CSRF(Cross Site Request Forgery, 跨站域请求伪造)是一种网络的×××方式。 我的理解是,比如你访问过招商银行的网站并登陆之后,你的cookie信息暂时不会...

Python实现多并发访问网站功能示例

本文实例讲述了Python实现多并发访问网站功能。分享给大家供大家参考,具体如下: # Filename:visitweb_threads.py # Description:pyth...

python使用TensorFlow进行图像处理的方法

一、图片的放大缩小 在使用TensorFlow进行图片的放大缩小时,有三种方式: 1、tf.image.resize_nearest_neighbor():临界点插值 2、tf.i...

python命令行参数sys.argv使用示例

复制代码 代码如下:#diff.py#!/bin/env python import sys if len(sys.argv) <> 3:   ...

运用PyTorch动手搭建一个共享单车预测器

运用PyTorch动手搭建一个共享单车预测器

本文摘自 《深度学习原理与PyTorch实战》 我们将从预测某地的共享单车数量这个实际问题出发,带领读者走进神经网络的殿堂,运用PyTorch动手搭建一个共享单车预测器,在实战过程中掌握...