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图形界面代码统计工具

本文为大家分享了python tkinter图形界面代码统计工具,供大家参考,具体内容如下 #encoding=utf-8 import os,sys,time from colle...

详解python--模拟轮盘抽奖游戏

详解python--模拟轮盘抽奖游戏

题目: 轮盘分为三部分: 一等奖, 二等奖和三等奖; 轮盘转的时候是随机的, 如果范围在[0,0.08)之间,代表一等奖, 如果范围在[0.08,0.3)之间,代表2等奖, 如果范围在[...

Python实现树莓派WiFi断线自动重连的实例代码

实现 WiFi 断线自动重连。原理是用 Python 监测网络是否断线,如果断线则重启网络服务。 1.Python 代码 autowifi.py,放在 /home/pi 目录下: #...

python实现堆和索引堆的代码示例

堆是一棵完全二叉树。堆分为大根堆和小根堆,大根堆是父节点大于左右子节点,并且左右子树也满足该性质的完全二叉树。小根堆相反。可以利用堆来实现优先队列。 由于是完全二叉树,所以可以使用数组来...

qpython3 读取安卓lastpass Cookies

之前我的博客写了python读取windows chrome Cookies,沿着同样的思路,这次本来想尝试读取安卓chrome Cookies, 但是可能是chrome的sqlite3...