【发布时间】:2020-12-04 19:59:27
【问题描述】:
为什么 fs.Renamesync 会在这里抛出错误:
this.parentDirectory = path.join(__dirname, '..', '..', 'Logs', serverType + '-logs');
this.logFilePath = path.resolve(this.parentDirectory, 'latest.log');
if (fs.existsSync(this.logFilePath)){
var newName = await firstLine(this.logFilePath);
newName += '.log';
fs.renameSync(this.logFilePath, path.join(this.parentDirectory, newName));
}
它是这样说的:
(node:648) UnhandledPromiseRejectionWarning: Error: ENOENT: no such file or directory, rename 'D:\Unity\Projects\FlipSide\Logs\room-logs\latest.log' -> 'D:\Unity\Projects\FlipSide\Logs\room-logs\Log-room-2020-08-14T22:58:20Z.log'
(不,这不是unity脚本,它是一个独立的节点服务器。)
文件存在,但不会重命名。
【问题讨论】:
-
target路径下的所有目录都存在吗? ENOENT 可能是关于它们的,而不是源文件。
-
@9000 是的,它只在文件存在时重命名,如果所有目录都不存在,它会在 existsSync 处抛出错误......对吧......?