Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

(Loop This code) For Each File in specific Folder

Status
Not open for further replies.

dianagele

Technical User
Nov 8, 2002
1
US
I am rusty with my vbscript.

I want to Loop this code "for every file in the folder":
(what it does: strip all quotes from each file)
note: this is borrowed code from the internet I use & like

Code:
' Define needed constants
Const ForReading = 1
Const ForWriting = 2
Const TriStateUseDefault = -2

' Get input file name from command line parm, if 2 parms entered
' use second as new output file, else rewrite to input file
If (WScript.Arguments.Count > 0) Then
  sInfile = WScript.Arguments(0)
Else
  WScript.Echo "No filename specified."
  WScript.Quit
End If
If (WScript.Arguments.Count > 1) Then
  sOutfile = WScript.Arguments(1)
Else
  sOutfile = sInfile
End If

' Create file system object
Set oFSO = CreateObject("Scripting.FileSystemObject")

' Read entire input file into a variable and close it
Set oInfile = oFSO.OpenTextFile(sInfile, ForReading, False, TriStateUseDefault)
sData = oInfile.ReadAll
oInfile.Close
Set oInfile = Nothing

' Remove unwanted characters
sData = Replace(sData, """", "")

' Write file with any changes made
Set oOutfile = oFSO.OpenTextFile(sOutfile, ForWriting, True)
oOutfile.Write(sData)
oOutfile.Close
Set oOutfile = Nothing

' Cleanup and end
Set oFSO = Nothing
Wscript.Quit


 
SOmething like this:

Code:
Set oFolder = oFSO.GetFolder("c:\somefolder")
For Each oFile in oFolder.Files
   Wscript.Echo oFile.Name
Next
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top