-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgetImageArrayTool.py
More file actions
38 lines (30 loc) · 1.19 KB
/
getImageArrayTool.py
File metadata and controls
38 lines (30 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# -*- coding: utf-8 -*-
import os
class GetImageTool(object):
def __init__(self):
self.imagearray = [];
self.imageDic = {};
# 遍历指定目录,显示目录下的所有文件名
def eachFile(self,filepath):
if os.path.isdir(filepath):
# print("it's a directory")
pathDir = os.listdir(filepath)
for allDir in pathDir:
if allDir == ".DS_Store":
continue
child = os.path.join(filepath, allDir)
# print(child) # .decode('gbk')是解决中文显示乱码问题
self.eachFile(child)
elif os.path.isfile(filepath):
lastPath = os.path.split(filepath)[1]
suffix = os.path.splitext(lastPath)[1]
lastPathName = os.path.splitext(lastPath)[0]
if suffix ==".png"or suffix==".jpg":
self.imagearray.append(lastPathName)
self.imageDic[lastPathName]=filepath;
else:
print("it's a special file (socket, FIFO, device file)")
print(filepath)
def getImageArrayWithFilePath(self,path):
self.eachFile(path)
return self.imagearray