Rename file in local directory

Post Reply
pradeepnitp
Newbie
Posts: 9
Joined: Tue Mar 18, 2014 3:17 pm

Rename file in local directory

Post 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.
dkelly
TOP CONTRIBUTOR
Posts: 658
Joined: Mon Nov 29, 2010 8:45 pm
Location: Alpharetta GA USA
Contact:

Rename file in local directory

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

pradeepnitp
Newbie
Posts: 9
Joined: Tue Mar 18, 2014 3:17 pm

Rename file in local directory

Post 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
dkelly
TOP CONTRIBUTOR
Posts: 658
Joined: Mon Nov 29, 2010 8:45 pm
Location: Alpharetta GA USA
Contact:

Rename file in local directory

Post 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.
pradeepnitp
Newbie
Posts: 9
Joined: Tue Mar 18, 2014 3:17 pm

Rename file in local directory

Post by pradeepnitp »

Thanks . It's working .
Post Reply