-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathFileUtil.py
More file actions
25 lines (23 loc) · 913 Bytes
/
FileUtil.py
File metadata and controls
25 lines (23 loc) · 913 Bytes
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
# -*- coding:utf8 -*-
import os,os.path
class FileUtil:
def __init__(self):
kad_id=0
@staticmethod
def get_file_info_from_path(dir,topdown=True):
dirinfo=[]
for root, dirs, files in os.walk(dir, topdown):
for name in files:
dirinfo.append(os.path.join(root,name))
return dirinfo
@staticmethod
def get_dir_info_from_path(dir,topdown=True):
fileinfo=[]
for root, dirs, files in os.walk(dir, topdown):
for name in dirs:
fileinfo.append(os.path.join(root,name))
return fileinfo
@staticmethod
def get_file_info_from_path_time_sorted(path):
mtime = lambda f: os.stat(os.path.join(path, f)).st_mtime
return list(sorted(os.listdir(path), key=mtime))