fs.rename(oldPath,
newPath, callback)
This
function renames the file asynchronously.
Below
table summarizes the arguments of ‘renameSync’ method.
Argument
|
Type
|
Description
|
oldPath
|
string
or Buffer or URL
|
Current
name or path of the file
|
newPath
|
string
or Buffer or URL
|
New
name or path of the file
|
Callback
|
Function
|
This
function takes one argument ‘err’ and it is called when rename call is
executed. On failure cases ‘err’ represents the stack trace.
|
var fs = require('fs'); var oldPath = 'input.txt'; // Assume input.txt file is already exist. var newPath = 'output.txt'; fs.rename(oldPath, newPath, (error) =>{ if(error){ console.log(`Error occured while renaming, ${error}`) }else{ console.log('Renamed successfuly'); } })
No comments:
Post a Comment