Yakalent
Yakalent

Reputation: 1152

Rename file in directory (Shelljs)

How can i rename a file into the same directory?

When i run this i've got the following error:

shell.cp('-R', './../../config/test.txt', './../../config/test1.txt');

I read the docs, but none of that answers my question.

Thanks for any help.

Upvotes: 1

Views: 892

Answers (1)

RobC
RobC

Reputation: 25032

Utilize the ShellJS mv() command to rename a file instead of the cp() command.

Assuming that the path definitions in your given example actually do exist, utilize the following instead:

var shell = require('shelljs');

shell.mv('./../../config/test.txt', './../../config/test1.txt');

Note: The ./ part at the beginning of each of the pathnames that you've provided seems to be redundant so you can omit that part too. For instance:

var shell = require('shelljs');

shell.mv('../../config/test.txt', '../../config/test1.txt');

Upvotes: 3

Related Questions