fs.rename(oldPath, newPath, callback)
oldPath
<string> | <Buffer> | <URL>newPath
<string> | <Buffer> | <URL>callback
<Function>err
<Error>
将 oldPath
处的文件异步重命名为作为 newPath
提供的路径名。
如果 newPath
已经存在,则它将被覆盖。
如果 newPath
是目录,则会引发错误。
除了可能的异常之外,没有为完成回调提供任何参数。
另见: rename(2)
。
import { rename } from 'node:fs';
rename('oldFile.txt', 'newFile.txt', (err) => {
if (err) throw err;
console.log('Rename complete!');
});
oldPath
<string> | <Buffer> | <URL>newPath
<string> | <Buffer> | <URL>callback
<Function>err
<Error>
Asynchronously rename file at oldPath
to the pathname provided
as newPath
. In the case that newPath
already exists, it will
be overwritten. If there is a directory at newPath
, an error will
be raised instead. No arguments other than a possible exception are
given to the completion callback.
See also: rename(2)
.
import { rename } from 'node:fs';
rename('oldFile.txt', 'newFile.txt', (err) => {
if (err) throw err;
console.log('Rename complete!');
});