Page 1 of 1

Rename file in local directory

Posted: Tue Mar 18, 2014 3:26 pm
by pradeepnitp
hi ,

I have a csv file as job and by reading this file I am navigating to local directory .I need to rename the files based on content of csv file .

I am using switch scripter for reading the csv file .

Is there any option to rename the file on local disk using switch javascript.

Rename file in local directory

Posted: Tue Mar 18, 2014 4:00 pm
by dkelly
Switch only has copy() and remove() functions. You could use the system() function to call OS move/mv command.



var oldName = job.getPath();

var newName = job.createPathWithName("NewName");

s.copy(oldName, newName);

File.remove(oldName);


Rename file in local directory

Posted: Tue Mar 18, 2014 6:55 pm
by pradeepnitp
HI ,

This is not working as the file that I want to rename is not a input job . I need to rename a file which is placed in local drive and not comming from job.



What I tried is



var fbxCompletePath = "E:Pradeeptest.fbx" ;



var newJob = s.createNewJob(fbxCompletePath);

var oldFileName = newJob.getPath();

var newName = E:Pradeepsuccess.fbx ;

var newFileName = job.createPathWithName(newName);

s.copy(oldFileName , newFileName);



but this is not working .

Please help

Rename file in local directory

Posted: Tue Mar 18, 2014 7:24 pm
by dkelly
If you just want to copy a file somewhere



s.copy("E:Pradeeptest.fbx", "E:Pradeepsuccess.fbx");





To move it



s.copy("E:Pradeeptest.fbx", "E:Pradeepsuccess.fbx");

File.remove("E:Pradeeptest.fbx");







A backslash in a string needs to be quoted.

Rename file in local directory

Posted: Wed Mar 19, 2014 11:16 am
by pradeepnitp
Thanks . It's working .