Unanswered question

How to rename a local file with javascrpt

using JavaScript, how to rename a file in my local drive like C:\Users\Public\TEMP\FileName.csv

I tried to use bat file with below script, its not working.


venkata S.
venkata S.

venkata S.

47 / 100


I'm not a JAVA or Javascript specialist but by googling a bit i found some examples of JAVA code to move a file to a different name using the code below:

var fileToCopy = new Packages.java.io.File("C:/Users/foo/AppData/Local/Temp/changeit.txt");
var NewName = new Packages.java.io.File("C:/Users/foo/AppData/Local/Temp/changeit2.txt");

if (NewName.exists())
   throw new java.io.IOException("file exists");

// Rename file (or directory)
var success =  fileToCopy.renameTo(NewName);

if (!success) {
   // File was not successfully renamed

I tried it and it worked fine.