Skip to content

Commit eb6c984

Browse files
author
minjk-bl
committed
FileNavigation - not showing hidden files or directories
1 parent d660932 commit eb6c984

File tree

1 file changed

+37
-17
lines changed

1 file changed

+37
-17
lines changed

src/api/functions/fileNaviCommand.py

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""
44

55
import os as _vp_os
6+
import stat as _vp_stat
67

78
def _vp_get_userprofile_path():
89
"""
@@ -64,9 +65,17 @@ def _vp_sizeof_fmt(num, suffix='B'):
6465
num /= 1024.0
6566
return '%.1f%s%s' % (num, 'Yi', suffix)
6667

67-
def _vp_search_path(path):
68+
def _vp_search_path(path, show_hidden=False):
6869
"""
6970
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
7079
"""
7180
import datetime as _dt
7281
_current = _vp_os.path.abspath(path)
@@ -76,20 +85,21 @@ def _vp_search_path(path):
7685
_info = []
7786
_info.append({'current':_current,'parent':_parent})
7887
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)})
93103
return _info
94104

95105
def _vp_get_image_by_path(path):
@@ -104,10 +114,20 @@ def _vp_get_relative_path(start, path):
104114
"""
105115
Get relative path using start path and current path
106116
start: str
107-
start path
117+
start path+
108118
path: str
109119
current path
110120
returns: str
111121
current relative path
112122
"""
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

Comments
 (0)