Thursday 18 October 2018

node.js: fs.renameSync(oldPath, newPath): Rename a file

fs.renameSync(oldPath, newPath)
This method is used to rename a file synchronously.

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

HelloWorld.js
var fs = require('fs');

var oldPath = 'input.txt'; // Assume input.txt file is already exist.
var newPath = 'output.txt';

fs.renameSync(oldPath, newPath)



Previous                                                 Next                                                 Home

No comments:

Post a Comment