• VBScript help: Re batch file and wildcard

    BrittneTabor Member

    Given this bit of vbs code:

    Const ForWriting = 2
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFile = objFSO.OpenTextFile("C:\Scripts\test.txt", ForWriting)
    objFile.Write "Some Text Goes Here"
    objFile.Close
    

    How can I make it so that I can use a wildcard (*.*), rather than test.txt as in the above? I have several different files I need to write a bit of text to, note not all are text files just for your info.

    I know I can use a batch file to do this, but I am going with vbs for it will contain vb specific code that I cannot spend alot of time trying to modify it then the result will be against what I am originally looking for.

  • SapnaVishwas Member

    You need to get a list of files in the directory/directories that you want and then loop through the writing function with each of the files.

    psuedocode:

    files = allFilesInThisDirectory("c:\scripts\")
    for i = 0 to files.count-1
    objFile = files(i)
    objFile.write "whatever"
    objFile.close
    next i
    
  • Adan Member

    I figured out how to recurse through a folder, but to write to all files in the folder I can’t find out how to do that. If I put a wildcard like *.js or *.php it don’t work, I get a bad filename or number error, if I remove the wildcard and replace that with the actual name, it will work. Any other suggestions?

Viewing 2 reply threads
  • You must be logged in to reply to this topic.