Commit 4d128676 authored by wanli's avatar wanli

update

parent cbb728ad
'''
Author: your name
Date: 2021-06-21 14:52:24
LastEditTime: 2021-06-22 12:08:31
LastEditTime: 2021-06-23 11:51:02
LastEditors: Please set LastEditors
Description: In User Settings Edit
FilePath: \evm-store\tools\modules\file-manager\main.py
......@@ -10,6 +10,8 @@ FilePath: \evm-store\tools\modules\file-manager\main.py
import os
import shutil
import pprint
from pathlib import PurePosixPath, PureWindowsPath
import platform
import json
from fs.osfs import OSFS
from fs import open_fs
......@@ -90,80 +92,62 @@ class FileManager(object):
type: "file"
}
'''
sys_str = platform.system()
# disk = "uploads" # disk就是文件根目录,只能以某个目录为根目录,浏览这个目录下面的所有文件
# target_path = None # 就是以disk为根目录的路径
# target_path = None # 就是以disk为根目录的路径,判断是否以**/**或者**\\**开头
if not target_path.startswith("/"):
target_path = "/" + target_path
result = {
"directories": [],
"files": []
}
disk_path = os.sep.join([disk_root, disk])
if not os.path.exists(disk_path):
return result
if not os.path.exists(os.path.normpath(os.sep.join([disk_path, target_path]))):
return result
os.chdir(disk_path)
print(os.getcwd())
home_fs = open_fs('.')
print(home_fs.tree())
for file in home_fs.scandir(target_path, namespaces=['details']):
if file.is_dir:
result["directories"].append({
tmp = {
"basename": file.name,
"dirname": os.path.basename(target_path),
"path": os.sep.join([target_path, file.name]),
"path": os.path.normpath(os.sep.join([target_path, file.name])),
"timestamp": int(file.raw.get("details").get("modified")),
"type": "dir"
})
}
if (sys_str == "Windows"):
p = PureWindowsPath(tmp.get("path"))
tmp["path"] = str(p.relative_to("\\"))
else:
p = PurePosixPath(tmp.get("path"))
tmp["path"] = str(p.relative_to('/'))
result["directories"].append(tmp)
else:
fn, ex = os.path.splitext(file.name)
result["files"].append({
tmp = {
"basename": file.name,
"dirname": os.path.basename(target_path),
"extension": ex[1:],
"filename": fn,
"path": os.sep.join([target_path, file.name]),
"path": os.path.normpath(os.sep.join([target_path, file.name])),
"size": file.size,
"timestamp": int(file.raw.get("details").get("modified")),
"type": "file"
})
print("//////////////////>>>>>>", file.name, file.size, file.suffix, file.path, dir(file))
# for file in os.listdir(target_path):
# print(">>>>>>>>>>>>>>>", os.getcwd(), os.path.relpath(target_path, os.getcwd()))
# if os.path.isdir(os.sep.join([target_path, file])):
# result["directories"].append({
# "basename": os.path.basename(file),
# "dirname": os.path.basename(target_path),
# "path": os.path.relpath(os.getcwd(), target_path),
# "timestamp": int(os.path.getatime(os.sep.join([target_path, file]))),
# "type": "dir"
# })
# else:
# fn, ex = os.path.splitext(file)
# result["files"].append({
# "basename": file,
# "dirname": os.path.basename(target_path),
# "extension": ex,
# "filename": fn,
# "path": os.path.relpath(os.getcwd(), os.sep.join([target_path, file])),
# "size": os.path.getsize(os.sep.join([target_path, file])),
# "timestamp": int(os.path.getmtime(os.sep.join([target_path, file]))),
# "type": "file"
# })
# print("file", file)
# for root, dirs, files in os.walk(os.getcwd(), topdown=False):
# for name in dirs:
# print(os.path.join(root, name), name)
# for name in files:
# print(os.path.join(root, name), name)
}
if (sys_str == "Windows"):
p = PureWindowsPath(tmp.get("path"))
tmp["path"] = str(p.relative_to("\\"))
else:
p = PurePosixPath(tmp.get("path"))
tmp["path"] = str(p.relative_to('/'))
result["files"].append(tmp)
home_fs.close()
with open("result.json", "w") as f:
......@@ -193,8 +177,14 @@ class FileManager(object):
}
'''
target_path = "./"
# for root, dirs, files in os.walk(os.getcwd(), topdown=False):
# for name in dirs:
# print(os.path.join(root, name), name)
# for name in files:
# print(os.path.join(root, name), name)
target_path = "./"
home_fs = OSFS(os.getcwd())
# 获取当前目录下所有目录、文件、子目录以及子文件的信息。递归获取
......@@ -243,5 +233,5 @@ if __name__ == "__main__":
result = fileManager.initialize()
print(result)
result = fileManager.content("uploads")
result = fileManager.content("uploads", "evueapps/evm")
print(result)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment