Link to home
Start Free TrialLog in
Avatar of Kimberly1467
Kimberly1467

asked on

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?
Avatar of basicinstinct
basicinstinct
Flag of Australia image

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
Avatar of Kimberly1467
Kimberly1467

ASKER

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?
are you asking for a shell or VB script?
ASKER CERTIFIED SOLUTION
Avatar of basicinstinct
basicinstinct
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial