VBScript to rename all files in a folder

I need a VBScript to rename all the files (that begin with the letters "test1") in a folder and then copy those renamed files to another folder.
Cad CoderDeveloperAsked:
Who is Participating?
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
I see now, the problem is the LIKE which does not exists in the VB Script.
Also, the MID( ) should use ,6 and not ,5 :-)

dim fso
set fso = createobject("Scripting.FilesystemObject")
dim folder
dim file

set folder = fso.GetFolder("C:\sourcefolder") 'put in the folder you want to look at
for each file in folder.files
   if ucase(left(file.name, 5)) = "TEST1" then
     fso.CopyFile "C:\sourcefolder\" & file.name , "C:\destinationfolder\" & mid(file.name, 6)
   end if  
next
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Ok....is there a pattern to how you want these files renamed?  Or can we just rename them using random characters?....
0
 
Cad CoderDeveloperAuthor Commented:
I need to strip off the "test1" the name of the file (keep the rest of the name).  For example a file named "test1File1.doc" would be named "File1.doc" and then copied to another folder.  I need the script to find all the files that begin with "test1" and then strip off the "test1" and save to another folder.  Sorry I didnot make that clear.
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
dim fso
set fso = createobject("Scripting.FilesystemObject")
dim folder
dim file

set folder = fso.GetFolder("C:\sourcefolder") 'put in the folder you want to look at
for each file in folder.files
   if file.name like "test1*" then
     fso.CopyFile "C:\sourcefolder\" & file.name , "C:\destinationfolder\" & mid(filename, 5)
   end if  
next

0
 
Cad CoderDeveloperAuthor Commented:
angelIII,

I got an error on line 8 - sub or function not defined.
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
sorry, I forgot a "." in the file.name in the mid() function call:

dim fso
set fso = createobject("Scripting.FilesystemObject")
dim folder
dim file

set folder = fso.GetFolder("C:\sourcefolder") 'put in the folder you want to look at
for each file in folder.files
   if file.name like "test1*" then
     fso.CopyFile "C:\sourcefolder\" & file.name , "C:\destinationfolder\" & mid(file.name, 5)
   end if  
next
0
 
Cad CoderDeveloperAuthor Commented:

Still get the same error after correcting the "mid(file.name, 5)".
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.