[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Script to change multiple file names

Posted on 2007-10-15
4
Medium Priority
?
912 Views
Last Modified: 2008-01-09
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?
0
Comment
Question by:Kimberly1467
  • 2
4 Comments
 
LVL 23

Expert Comment

by:basicinstinct
ID: 20081675
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
 

Author Comment

by:Kimberly1467
ID: 20084974
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
 
LVL 51

Expert Comment

by:ahoffmann
ID: 20091339
are you asking for a shell or VB script?
0
 
LVL 23

Accepted Solution

by:
basicinstinct earned 2000 total points
ID: 20091558
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

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
This article will show, step by step, how to integrate R code into a R Sweave document
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses
Course of the Month20 days, 2 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question