python搜索指定目录的方法

yipeiwu_com6年前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读取txt内容写入xls格式excel中的方法

由于xlwt目前只支持xls格式,至于xlsx格式,后面会继续更新 import xlwt import codecs def Txt_to_Excel(inputTxt,shee...

python自动化工具日志查询分析脚本代码实现

受控节点slave.py 复制代码 代码如下:import socketimport reclass Log(object):    file_list=[...

numpy中的meshgrid函数的使用

numpy官方文档meshgrid函数帮助文档https://docs.scipy.org/doc/numpy/reference/generated/numpy.meshgrid.ht...

ipad上运行python的方法步骤

ipad上可以运行python么? ipad上是可以运行python的。 1、在我们的ipad上百度搜索Python,点击进去。 2、进去网站之后,点击"Downloads->Wi...

python统计文本文件内单词数量的方法

本文实例讲述了python统计文本文件内单词数量的方法。分享给大家供大家参考。具体实现方法如下: # count lines, sentences, and words of a t...