Thursday, January 8, 2015

windows - Rename multiple files in sequence through command line


I have 9873 files in a folder on hard-drive that are named as



  • myname-script.sql.001

  • myname-script.sql.002

  • and so on


Now I need to rename these files to



  • myname-script.001.sql

  • myname-script.002.sql

  • and so on


I want to name them all at once through command line.


Answer



You can use vbscript to rename



Set fso = CreateObject("Scripting.FileSystemObject")


set oFldr = fso.getfolder("C:\file\path")


for each ofile in oFldr.Files


splited = Split(ofile.Name, ".", -1, 1)


ofile.name = splited(0) & "." & splited(2) & "." & splited(1)


Next



This script will split your file name via the . and then re-arrange it to swap the 2nd and 3rd extensions


No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...