File_File_Move 目标为已存在目录时自动移入该目录
此前 pathDest 被固定当作完整目标文件路径, 目标填分类目录时 rename(文件->目录)失败, fallback cp 报 ENOTDIR(cannot overwrite directory with non-directory), 文件整理类流程无法用目录作目标。 现在目标存在且为目录时自动拼接源文件名(移入语义), 目标不存在 仍按完整文件路径处理。 附: 晨间助手全家桶测试流程生成脚本(30节点, 文件整理+记事本 键鼠+Excel加工+OCR/AI)
This commit is contained in:
1 parent
b59d906161
commit
902ee0cec4
2 files changed
+202
No files matched your search
@@ -92,6 +92,16 @@ register(["File_File_Move", "File_Move"], async (_ctx, node, args) => {
|
||||
const newName = truthy(args.rename) ? pick(args, ["name"]) : "";
|
||||
target = requirePath(newName ? path.join(destDir, newName) : destDir, "目的地路径", node.id, node.componentId);
|
||||
}
|
||||
let targetStat: import("node:fs").Stats | null = null;
|
||||
try {
|
||||
targetStat = await fs.stat(target);
|
||||
} catch {
|
||||
// 目标不存在,按完整文件路径处理
|
||||
}
|
||||
if (targetStat?.isDirectory()) {
|
||||
// 目标是已存在的目录:语义为“移入该目录”,自动拼上源文件名
|
||||
target = path.join(target, path.basename(source));
|
||||
}
|
||||
await fs.mkdir(path.dirname(target), { recursive: true });
|
||||
try {
|
||||
await fs.rename(source, target);
|
||||
|
||||
Reference in new issue
Block a user