nihylo Posted July 28, 2008 Share Posted July 28, 2008 Hi,I'm trying to use a wildcard for my text-replacing script but unfortunately, all of my previous attempts failed...Const ForReading = 1Const ForWriting = 2Set objFSO = CreateObject("Scripting.FileSystemObject")Set objFile = objFSO.OpenTextFile("bla.txt", ForReading)strText = objFile.ReadAllobjFile.ClosestrNewText = Replace(strText, "tutu", "tata")Set objFile = objFSO.OpenTextFile("bla.txt", ForWriting)objFile.WriteLine strNewTextobjFile.CloseI just want to specify "*.txt" rather than "bla.txt"Thanks by advance Link to comment Share on other sites More sharing options...
CoffeeFiend Posted July 28, 2008 Share Posted July 28, 2008 (edited) The OpenTextFile method only opens one file (returns 1 file handle), so using a wildcard there doesn't even make sense.If you want to process more than one file, you'll have to enumerate them first, and then process them one by one.Also, just wondering why you're even doing this. Unless you have very specific needs that would be solved by a specialized app or script, there's no point in wasting time reinventing the wheel poorly. The "text replace in files" problem has been mostly solved since pretty much forever, using standard utils like sed (which has been around for 30+ years).What you seem to want to do (replace "tutu" by "tata" in *.txt) is trivial to do using sed:sed -i "s/tutu/tata/g" *.txtAll done...-i -> edit the files (not make copies)s -> substituteg -> global Edited July 28, 2008 by crahak Link to comment Share on other sites More sharing options...
nihylo Posted July 28, 2008 Author Share Posted July 28, 2008 You're right, I'll better go with sed. Thanks. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now