首页 > 解决方案 > 节点文件系统模块重命名方法

问题描述

我正在尝试使用文件系统库中的重命名方法更改文件名,文件名已更改,但出现如下错误:

const fs = require("fs");
fs.renameSync("./name.js", "anothername.js");

Error: ENOENT: no such file or directory, rename './changed.js' -> 'another.js'
    at Object.renameSync (fs.js:614:3)
    at Object.<anonymous> (/home/lenovo/Desktop/test.js:2:4)
    at Module._compile (internal/modules/cjs/loader.js:738:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:749:10)
    at Module.load (internal/modules/cjs/loader.js:630:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:570:12)
    at Function.Module._load (internal/modules/cjs/loader.js:562:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:801:12)
    at internal/main/run_main_module.js:21:11

标签: javascriptnode.js

解决方案


推荐阅读