在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如何在前程无忧高效投递简历

前言 在前程无忧上投递简历发现有竞争力分析,免费能看到匹配度评价和综合竞争力分数,可以做投递参考 计算方式 综合竞争力得分应该越高越好,匹配度评语也应该评价越高越好 抓取所有职位关键...

Pycharm以root权限运行脚本的方法

Pycharm以root权限运行脚本的方法

因为权限不够,导致Pycharm在运行脚本时报错: socket.error: [Errno 1] Operation not permitted 网上有一些修改文件使得Pycha...

python银行系统实现源码

本文实例为大家分享了python实现银行系统的具体代码,供大家参考,具体内容如下 1、admin.py 定义管理员信息和主界面显示 #!/usr/bin/env python # c...

python实现图片批量压缩程序

 本文实例为大家分享了python实现图片批量压缩程序的具体代码,供大家参考,具体内容如下 说明 运行环境:Win10 Pycharm 程序没有用到面向对象编程方法,...

python+matplotlib绘制简单的海豚(顶点和节点的操作)

python+matplotlib绘制简单的海豚(顶点和节点的操作)

海豚 本文例子主要展示了如何使用补丁、路径和转换类绘制和操作给定的顶点和节点的形状。 测试可用。 import matplotlib.cm as cm import matplotl...