3
3
"""
4
4
5
5
import os as _vp_os
6
+ import stat as _vp_stat
6
7
7
8
def _vp_get_userprofile_path ():
8
9
"""
@@ -64,9 +65,17 @@ def _vp_sizeof_fmt(num, suffix='B'):
64
65
num /= 1024.0
65
66
return '%.1f%s%s' % (num , 'Yi' , suffix )
66
67
67
- def _vp_search_path (path ):
68
+ def _vp_search_path (path , show_hidden = False ):
68
69
"""
69
70
Search child folder and file list under the given path
71
+ path: str
72
+ path to search file/dir list
73
+ show_hidden: bool (optional; default: False)
74
+ set True for show hidden file/dir
75
+ returns: list
76
+ list with scanned file/dir list
77
+ 0 element with current and parent path information
78
+ 1~n elements with file/dir list under given path
70
79
"""
71
80
import datetime as _dt
72
81
_current = _vp_os .path .abspath (path )
@@ -76,20 +85,21 @@ def _vp_search_path(path):
76
85
_info = []
77
86
_info .append ({'current' :_current ,'parent' :_parent })
78
87
for _entry in i :
79
- _name = _entry .name
80
- _path = _entry .path # 파일 경로
81
- _stat = _entry .stat ()
82
- _size = _vp_sizeof_fmt (_stat .st_size ) # 파일 크기
83
- _a_time = _stat .st_atime # 최근 액세스 시간
84
- _a_dt = _dt .datetime .fromtimestamp (_a_time ).strftime ('%Y-%m-%d %H:%M' )
85
- _m_time = _stat .st_mtime # 최근 수정 시간
86
- _m_dt = _dt .datetime .fromtimestamp (_m_time ).strftime ('%Y-%m-%d %H:%M' )
87
- _e_type = 'other'
88
- if _entry .is_file ():
89
- _e_type = 'file'
90
- elif _entry .is_dir ():
91
- _e_type = 'dir'
92
- _info .append ({'name' :_name , 'type' :_e_type , 'path' :_path , 'size' :_size , 'atime' :str (_a_dt ), 'mtime' :str (_m_dt )})
88
+ if show_hidden or _vp_check_hidden (_entry .path ) == False :
89
+ _name = _entry .name
90
+ _path = _entry .path # 파일 경로
91
+ _stat = _entry .stat ()
92
+ _size = _vp_sizeof_fmt (_stat .st_size ) # 파일 크기
93
+ _a_time = _stat .st_atime # 최근 액세스 시간
94
+ _a_dt = _dt .datetime .fromtimestamp (_a_time ).strftime ('%Y-%m-%d %H:%M' )
95
+ _m_time = _stat .st_mtime # 최근 수정 시간
96
+ _m_dt = _dt .datetime .fromtimestamp (_m_time ).strftime ('%Y-%m-%d %H:%M' )
97
+ _e_type = 'other'
98
+ if _entry .is_file ():
99
+ _e_type = 'file'
100
+ elif _entry .is_dir ():
101
+ _e_type = 'dir'
102
+ _info .append ({'name' :_name , 'type' :_e_type , 'path' :_path , 'size' :_size , 'atime' :str (_a_dt ), 'mtime' :str (_m_dt )})
93
103
return _info
94
104
95
105
def _vp_get_image_by_path (path ):
@@ -104,10 +114,20 @@ def _vp_get_relative_path(start, path):
104
114
"""
105
115
Get relative path using start path and current path
106
116
start: str
107
- start path
117
+ start path+
108
118
path: str
109
119
current path
110
120
returns: str
111
121
current relative path
112
122
"""
113
- return _vp_os .path .relpath (path , start )
123
+ return _vp_os .path .relpath (path , start )
124
+
125
+ def _vp_check_hidden (path ):
126
+ """
127
+ Check if it's hidden
128
+ path: str
129
+ file path
130
+ returns: bool
131
+ True for hidden file/dir, False for others
132
+ """
133
+ return bool (_vp_os .stat (path ).st_file_attributes & _vp_stat .FILE_ATTRIBUTE_HIDDEN )
0 commit comments