This repository has been archived on 2020-04-18. You can view files and clone it, but cannot push or open issues or pull requests.
photo/photo/util/fileUtil.py

49 lines
1.2 KiB
Python

#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
import os
import json
allow_pics = ['png', 'jpg', 'jpeg']
def get_all_pics(path):
pics = []
for file in os.listdir(path):
file_path = os.path.join(path, file)
if os.path.isdir(file_path):
continue
allow_type = False
for pic_type in allow_pics:
if str(file).lower().endswith(pic_type):
allow_type = True
break
if allow_type:
pics.append(file)
return pics
def get_all_folds(path):
folds = []
for fold in os.listdir(path):
fold_path = os.path.join(path, fold)
if os.path.isdir(fold_path):
entity = {'fold': fold, 'fold_path': fold_path}
folds.append(entity)
return folds
def read_file_json(path):
if not os.path.exists(path) or not os.path.isfile(path):
return json.loads('{"name": "default", "des":"默认描述"}')
f = open(path, 'r')
lines = f.readlines()
json_str = ""
for line in lines:
json_str += line
return json.loads(json_str)
# path = "/home/zeek/project/photo/static/img"
# pics = get_all_pics(path)
# print(pics)