在Python中移动目录结构的方法
更新时间:2016年01月31日 21:41:30 投稿:mdxy-dxy
这篇文章主要介绍了在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/list/tuple)相互转换方法及join()函数的使用
这篇文章主要介绍了python3 字符串/列表/元组(str/list/tuple)相互转换方法及join()函数的使用 ,非常不错,具有一定的参考借鉴价值,需要的朋友可以参考下2019-04-04
python中的socket实现ftp客户端和服务器收发文件及md5加密文件
这篇文章主要介绍了python中的socket实现ftp客户端和服务器收发文件及md5加密文件的相关知识,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下2020-04-04


最新评论