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的CGIHTTPServer交互实现详解

Python的CGIHTTPServer交互实现详解

介绍 对于服务器后端开发者而言,有时候需要把自己的一些服务直接暴露给PM或者其他RD使用,这个时候需要搭建一套web服务可以和前端用户做简单交互,按照最常规的做法,一般是用Apache或...

Python3.6.x中内置函数总结及讲解

Python3.6.x中内置函数总结 # -*- coding:utf-8 -*- """ abs() dict() help() min() s...

Python中内建函数的简单用法说明

Python提供了一个内联模块buildin,该模块定义了一些软件开发中经常用到的函数,利用这些函数可以实现数据类型的转换、数据的计算、序列的处理等。 buildin模块的内置函数: 1...

使用Python AIML搭建聊天机器人的方法示例

AIML全名为Artificial Intelligence Markup Language(人工智能标记语言),是一种创建自然语言软件代理的XML语言,是由RichardS. Wall...

使用django-crontab实现定时任务的示例

今天打算在自己的 Django 应用中添加一个定时任务来定时执行一些定期检查的功能,因此想到了使用 django-crontab 插件可以满足我的需求,下面就是这个插件的使用方法。 首先...