python搜索指定目录的方法

yipeiwu_com5年前Python基础

本文实例讲述了python搜索指定目录的方法。分享给大家供大家参考。具体分析如下:

#-------------------------------------
#      Name: search_directory.py
#     Author: Kevin Harris
# Last Modified: 02/13/04
# Description: This Python script demonstrates how to use os.walk()
#         to walk through a directory hierarchy
#         and list everything 
#         found.
#-------------------------------------
import os
for root, dirs, files in os.walk( os.curdir ):
 print( "root = " + root )
 for file in files:
 print( "file = " + file )
 for dir in dirs:
 print( "dir = " + dir )
 print( "\n" )
input( '\n\nPress Enter to exit...' )

希望本文所述对大家的Python程序设计有所帮助。

相关文章

python计算时间差的方法

本文实例讲述了python计算时间差的方法。分享给大家供大家参考。具体分析如下: 1、问题: 给定你两个日期,如何计算这两个日期之间间隔几天,几个星期,几个月,几年? 2、解决方法: 标...

python groupby 函数 as_index详解

在官方网站中对as_index有以下介绍: as_index : boolean, default True For aggregated output, return object w...

黑科技 Python脚本帮你找出微信上删除你好友的人

黑科技 Python脚本帮你找出微信上删除你好友的人

相信大家在微信上一定被上面的这段话刷过屏,群发消息应该算是微信上流传最广的找到删除好友的方法了。但群发消息不仅仅会把通讯录里面所有的好友骚扰一遍,而且你还得挨个删除好几百个聊天记录,回复...

Python PyQt4实现QQ抽屉效果

Python PyQt4实现QQ抽屉效果

本文实例为大家分享了Python PyQt4实现QQ抽屉效果展示的具体代码,供大家参考,具体内容如下 先看截图效果: 主要是使用了QT的QTabWidget、QToolBox多页窗口部...

Python的__builtin__模块中的一些要点知识

1.isinstance函数:除了以一个类型作为参数,还可以以一个类型元组作为参数。 isinstance(obj,basestring)===isinstance(obj,(str...