Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

file extension in vbscript

Posted on 2007-04-03
9
Medium Priority
?
420 Views
Last Modified: 2010-04-30
hi i have this vbs code that read through a folde and replace text in files but i only want it to replace files with extension "dot". what change must i make. here the code

'ReplaceFile.vbs
Dim objFile, objOutput
Dim objFSO: Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objFolder: Set objFolder=objFSO.GetFolder("C:\BatchTest\")
OldData = ".2220"
NewData = ".222011"
document.write("Hello from VBScript!")
For Each file in objFolder.Files
 
  Set objFile = objFSO.OpenTextFile(file)
  arrData = Replace(objFile.ReadAll, OldData, NewData)
  objFile.Close
  Set objOutput = objFSO.CreateTextFile(file)
  objOutput.Write arrData
  objOutput.Close
  Set objOutput=Nothing
  Set objFile=Nothing

Next

Set objFSO=Nothing
0
Comment
Question by:eaweb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
9 Comments
 
LVL 67

Expert Comment

by:sirbounty
ID: 18845672
This should do it. :^)


'ReplaceFile.vbs
Dim objFile, objOutput
Dim objFSO: Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objFolder: Set objFolder=objFSO.GetFolder("C:\BatchTest\")
OldData = ".2220"
NewData = ".222011"
document.write("Hello from VBScript!")
For Each file in objFolder.Files
  If objFSO.GetExtensionName="dot" Then
    Set objFile = objFSO.OpenTextFile(file)
    arrData = Replace(objFile.ReadAll, OldData, NewData)
    objFile.Close
    Set objOutput = objFSO.CreateTextFile(file)
    objOutput.Write arrData
    objOutput.Close
    Set objOutput=Nothing
    Set objFile=Nothing
  End If
Next

Set objFSO=Nothing
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18845679
...just to be sure though, use this line instead...ensures the case matches...

 If lCase(objFSO.GetExtensionName)="dot" Then
0
 

Author Comment

by:eaweb
ID: 18845747
it doesn't seem to work:

i get the smg when running it from command of
vbscript runtime error: type mismatch

here the code again

'ReplaceFile.vbs
Dim objFile, objOutput, ext
Dim objFSO: Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objFolder: Set objFolder=objFSO.GetFolder("C:\BatchTest\")
OldData = ".20002"
NewData = ".2020202"

For Each file in objFolder.Files
If lCase(objFSO.GetExtensionName)="dot" Then

  Set objFile = objFSO.OpenTextFile(file)
  arrData = Replace(objFile.ReadAll, OldData, NewData)
  objFile.Close
  Set objOutput = objFSO.CreateTextFile(file)
  objOutput.Write arrData
  objOutput.Close
  Set objOutput=Nothing
  Set objFile=Nothing
end if
Next

Set objFSO=Nothing

and could you advice me also how to display text in vbs because it doesn't work with document.write with me
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 67

Accepted Solution

by:
sirbounty earned 2000 total points
ID: 18845761
Posted too quickly...sorry about that...try this please:

If lCase(objFSO.GetExtensionName(file.name))="dot" Then
0
 

Author Comment

by:eaweb
ID: 18845801
and how do i display (echo) a message in vbscript in th cmd
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18845810
Sorry?  I don't understand...?
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18845814
wscript.echo "Your message"
is the way to display a message...
0
 

Author Comment

by:eaweb
ID: 18845895
YES!!!!!!!

that's it.

Thanks
0
 
LVL 67

Expert Comment

by:sirbounty
ID: 18845904
Happy to help :^)
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

636 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