1

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');

  • cp: dest is not a directory (too many sources)

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

Thanks for any help.

Yakalent
  • 1,142
  • 2
  • 10
  • 18

1 Answers1

3

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');
RobC
  • 22,977
  • 20
  • 73
  • 80