首页 > 编程语言 > 详细

Python语言获取目录下所有文件

时间:2017-03-17 00:05:38      阅读:275      评论:0      收藏:0      [点我收藏+]

#coding=utf-8
# -*- coding: utf-8 -*-
import os
import sys
reload(sys)
sys.setdefaultencoding(‘utf-8‘)

def GetFileList(dir, fileList):
  newDir = dir
  if os.path.isfile(dir):
    fileList.append(dir.decode(‘gbk‘))
  elif os.path.isdir(dir):
    for s in os.listdir(dir):
    #如果需要忽略某些文件夹,使用以下代码
    #if s == "xxx":
    #continue
    newDir=os.path.join(dir,s)
    GetFileList(newDir, fileList)
  return fileList


list = GetFileList(‘D:\\python\\work\\cp1\\game_name‘, [])

Python语言获取目录下所有文件

原文:http://www.cnblogs.com/monsteryang/p/6562143.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!