Code with C | Programming: Projects & Source Codes › Forums › Visual Basic Classic › VBScript help: Re batch file and wildcard
October 12, 2016 at 3:56 pm #10677
Given this bit of vbs code:12345Const ForWriting = 2Set 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.
October 12, 2016 at 3:57 pm #10678
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:123456files = allFilesInThisDirectory("c:\scripts\")for i = 0 to files.count-1objFile = files(i)objFile.write "whatever"objFile.closenext i
October 12, 2016 at 3:57 pm #10679
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?
You must be logged in to reply to this topic.