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的Tkinter点击按钮触发事件的例子

Python的Tkinter点击按钮触发事件的例子

如果要开发一个比较大的程序,那么应该先把代码封装起来,在面向对象编程中,就是封装成类 先看代码: import tkinter as tk class App: def __in...

Linux下编译安装MySQL-Python教程

1、下载mysql-python 官网地址:http://sourceforge.net/projects/mysql-python/ 2、安装mysql-python 复制代码 代码如...

Python 3 使用Pillow生成漂亮的分形树图片

Python 3 使用Pillow生成漂亮的分形树图片

该程序通过绘制树干(最初是树;后来是树枝)并递归地添加树来绘制“树”。 使用Pillow。 利用递归函数绘制分形树(fractal tree),分形几何学的基本思想:客观事物具有自相似的...

Python字符串格式化输出方法分析

本文实例分析了Python字符串格式化输出方法。分享给大家供大家参考,具体如下: 我们格式化构建字符串可以有3种方法: 1 元组占位符 m = 'python' astr = 'i...

Python实现保证只能运行一个脚本实例

保证只能运行一个脚本实例,方法是程序运行时监听一个特定端口,如果失败则说明已经有实例在跑。 使用装饰器实现,便于重用 复制代码 代码如下: import functools def ju...