在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 3实现发送邮件功能

下面一段简短代码给大家介绍python 3实现发送邮件功能,具体代码如下所示: import smtplib from email.mime.text import MIMEText...

Python 获取新浪微博的最新公共微博实例分享

API: statuses/public_timeline  返回最新的200条公共微博,返回结果非完全实时 CODE: #!/usr/bin/python # -*-...

django rest framework 实现用户登录认证详解

django rest framework 实现用户登录认证详解

1、安装 pip install djangorestframework 2、创建项目及应用 创建项目 创建应用 目录结构如图 3、设置settings.py 设置数据库...

python多个模块py文件的数据共享实例

模块a.py 想用 b.py中公有数据 cnt b的python文件 #!/usr/bin/env python # coding:utf8 from wx import Cal...

python获取糗百图片代码实例

复制代码 代码如下:from sgmllib import SGMLParserimport urllib2 class sgm(SGMLParser):  &nbs...