-
如题,求教。 |
Beta Was this translation helpful? Give feedback.
Answered by
m3lab-zzl
Dec 23, 2023
Replies: 1 comment 1 reply
-
google 一下你就知道,我找到了一个看起来还行的脚本,供参考 import os
import shutil
assets_dir = './assets'
journal_dir = './journals'
pages_dir = './pages'
to_delete_dir = './to_delete'
if not os.path.exists(to_delete_dir):
os.makedirs(to_delete_dir)
referenced_files = set()
for dirname in [journal_dir, pages_dir]:
for filename in os.listdir(dirname):
if filename.endswith('.md'):
# 打开 .md 文件
with open(os.path.join(dirname, filename), encoding="UTF-8") as f:
# 遍历文件中的每一行
for line in f:
# 遍历 assets 目录中的所有文件
for asset in os.listdir(assets_dir):
# 如果这一行包含了 assets 目录中的某个文件的名称,则将这个文件的名称加入到 referenced_files 集合中
if asset in line:
referenced_files.add(asset)
for asset in os.listdir(assets_dir):
if asset not in referenced_files and not asset.endswith(".edn"):
print(asset)
shutil.move(os.path.join(assets_dir, asset), to_delete_dir) 把它放到你logseq项目主目录里,与asserts,journals同级,然后python运行它就行,都会被挪到to_delete文件夹下,确认无误后可以手动删除这个文件夹 |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
X012C
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
google 一下你就知道,我找到了一个看起来还行的脚本,供参考