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的Django框架与认证系统整合的方法

将Django与其他现有认证系统的用户名和密码或者认证方法进行整合是可以办到的。 例如,你所在的公司也许已经安装了LDAP,并且为每一个员工都存储了相应的用户名和密码。 如果用户在LDA...

python 3.7.0 安装配置方法图文教程

python 3.7.0 安装配置方法图文教程

本文记录了python 3.7.0 安装配置方法,供大家参考,具体内容如下 S1 登入Python官网下载网址 S2 下载后缀为exe的可执行文件,并根据自己电脑/主机的系统选择32位还...

Python管理Windows服务小脚本

本文实例为大家分享了Python管理Windows服务的具体代码,供大家参考,具体内容如下 #!/usr/bin/python # encoding: utf-8 # -*- cod...

Python编程实现从字典中提取子集的方法分析

本文实例讲述了Python编程实现从字典中提取子集的方法。分享给大家供大家参考,具体如下: 首先我们会想到使用字典推导式(dictionary comprehension)来解决这个问题...

Python3+django2.0+apache2+ubuntu14部署网站上线的方法

Python3+django2.0+apache2+ubuntu14部署网站上线的方法

自己尝试在本地搭建了 Django 项目后,想部署到自己云服务器上,经常多次尝试和多次踩坑(捂脸),总结如下: 环境:ubuntu14, django2.0, apache2。 1.首先...