初始化提交

This commit is contained in:
王立帮
2024-07-19 10:16:00 +08:00
parent 4c7b571f20
commit 4a2d56dcc4
7084 changed files with 741212 additions and 63 deletions

View File

@@ -0,0 +1,37 @@
try:
import os
except ImportError:
import uos as os
def check_path(path):
try:
stat = os.stat(path)
# The first element of stat contains the file type and permission information
# The mode index of the tuple returned by os.stat() is 0
mode = stat[0]
# To determine whether it is a directory, check the directory bit in stat mode
if mode & 0o170000 == 0o040000:
if len(os.listdir(path)):
return 'dir'
else:
return 'empty dir'
# To determine whether it is a file, check the file position in stat mode
elif mode & 0o170000 == 0o100000:
return 'file'
else:
return 'special file'
except OSError:
return 'none'
def listdir(directory):
output = []
if directory == '/':
dirs = sorted([directory + f for f in os.listdir(directory)])
else:
dirs = sorted([directory + '/' + f for f in os.listdir(directory)])
for dir in dirs:
output.append([dir, check_path(dir)])
return output
print(listdir('{{&path}}'))