Script to change multiple file names

I need to know how to write a script that will change the name of my logfiles. For example if I have the following files:
ex071014log.txt
ex071015log.txt
I want to  change each one to:
Han-Soloex071014log.txt
Han-Soloex071015log.txt

In essence I want to add Han-Solo in front of the original file name.
Can this be done, if so how?
Kimberly1467Asked:
Who is Participating?
 
basicinstinctConnect With a Mentor Commented:
Const FullPath = "C:\path\to\your\dir"
Const Prefix = "Han-Solo"
Dim fso, directory, fileList, oFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set directory = fso.GetFolder(FullPath)
Set fileList = directory.files

For Each oFile in fileList
 Dim i
 i = instr(oFile.name, Prefix)
 if(i < 1)then
   oFile.name = Prefix + oFile.name
 end if
Next
0
 
basicinstinctCommented:
easy with filesystemobject

Dim FullPath
FullPath = "C:\path\to\your\folder"
Dim fso, directory, fileList, oFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set directory = fso.GetFolder(FullPath)
Set fileList = directory.files

For Each oFile in fileList
 oFile.name = "Han-Solo" + oFile.name
Next
0
 
Kimberly1467Author Commented:
basicinstinct,

That works great! But I want to add this to a scheduled task that runs everyday at 10:00 am. But when I do this the file name that was change the day before to Hans-Soloex071024log now becomes Han-SoloHanSoloex071024log. Is there a way not change the file name of those that have previously been changed?
0
 
ahoffmannCommented:
are you asking for a shell or VB script?
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.