goddy
15-11-2010, 09:24
Chả là em đang cần 1 tool hay 1 script trên win có thể edit nội dung trong nhiều file text nhưng ko biết làm thế nào :D. Search google có tìm đc 1 script replace.vbs edit 1 file text như sau:
Const ForReading = 1
Const ForWriting = 2
strFileName = Wscript.Arguments(0)
strOldText = Wscript.Arguments(1)
strNewText = Wscript.Arguments(2)
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strFileName, ForReading)
strText = objFile.ReadAll
objFile.Close
strNewText = Replace(strText, strOldText, strNewText)
Set objFile = objFSO.OpenTextFile(strFileName, ForWriting)
objFile.WriteLine strNewText
objFile.Close
và file .bat để run script trên có nội dung:
cscript replace.vbs "longlx.txt" "Y:" "E:"
lệnh trên sẽ đổi các ký tự "Y:" thành "E:" trong file longlx.txt
Tuy nhiên với lệnh đó e chỉ tác động lên đc 1 file txt thôi :sad:, giờ em muốn có thể tác động lên nhiều file .txt nhưng lệnh trên ko làm được (em thay longlx.txt thành *.txt mà ko đc :((). Anh em biết về những cái này giúp em với ạ, đang cần gấp ạ :sosad: . Thanks anh em........
Const ForReading = 1
Const ForWriting = 2
strFileName = Wscript.Arguments(0)
strOldText = Wscript.Arguments(1)
strNewText = Wscript.Arguments(2)
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strFileName, ForReading)
strText = objFile.ReadAll
objFile.Close
strNewText = Replace(strText, strOldText, strNewText)
Set objFile = objFSO.OpenTextFile(strFileName, ForWriting)
objFile.WriteLine strNewText
objFile.Close
và file .bat để run script trên có nội dung:
cscript replace.vbs "longlx.txt" "Y:" "E:"
lệnh trên sẽ đổi các ký tự "Y:" thành "E:" trong file longlx.txt
Tuy nhiên với lệnh đó e chỉ tác động lên đc 1 file txt thôi :sad:, giờ em muốn có thể tác động lên nhiều file .txt nhưng lệnh trên ko làm được (em thay longlx.txt thành *.txt mà ko đc :((). Anh em biết về những cái này giúp em với ạ, đang cần gấp ạ :sosad: . Thanks anh em........