欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Python實(shí)現(xiàn)遍歷目錄的方法【測(cè)試可用】

 更新時(shí)間:2017年03月22日 10:54:51   作者:聰明的狐貍  
這篇文章主要介紹了Python實(shí)現(xiàn)遍歷目錄的方法,涉及Python針對(duì)目錄與文件的遍歷、判斷、讀取相關(guān)操作技巧,需要的朋友可以參考下

本文實(shí)例講述了Python實(shí)現(xiàn)遍歷目錄的方法。分享給大家供大家參考,具體如下:

# *-* coding=gb2312 *-*
import os.path
import shutil
def traveltree(curPath,count):
  if not os.path.exists(curPath):
    return
  if os.path.isfile(curPath):
    fileName =os.path.basename(curPath)
    print '\t' *count+ '├─' + fileName
  elif os.path.isdir(curPath):
    print '\t' *count+ '├─' + curPath
    pathlist =os.listdir(curPath)
    for aa in pathlist:
      traveltree(curPath +"\\"+aa,count+1)
if __name__=='__main__':
  traveltree("C:\\py",1)

運(yùn)行效果圖如下:

更多關(guān)于Python相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Python文件與目錄操作技巧匯總》、《Python圖片操作技巧總結(jié)》、《Python數(shù)據(jù)結(jié)構(gòu)與算法教程》、《Python Socket編程技巧總結(jié)》、《Python函數(shù)使用技巧總結(jié)》、《Python字符串操作技巧匯總》、《Python編碼操作技巧總結(jié)》及《Python入門(mén)與進(jìn)階經(jīng)典教程

希望本文所述對(duì)大家Python程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論