' Script per Sostituzione di massa stringhe in file' Massive text in file substution
Set oFSO = CreateObject("Scripting.FileSystemObject")Set
objShell = WScript.CreateObject( "WScript.Shell" )
Set fOut = oFSO.CreateTextFile("StringInFileSubstitution.txt", True)
Dim FileName, Find,
ReplaceWith, FileContents, dFileContents, PathDirDim NomeP
Dim OutPut
'Modifica file nella cartella
Find = Inputbox ("Inserisci la stringa da cercare nei file","The Patcher","pippo")
ReplaceWith = Inputbox ("Inserisci la stringa da sostituire a " + Find ,"The Patcher","pippa")
PathDir = Inputbox ("Inserisci il path da cui partire","The
Patcher","C:\Test1")
DoStuff oFSO.GetFolder(PathDir).Path,Find,ReplaceWith
'Read text filefunction Fix(FileName, Find, ReplaceWith)
'Read source text
fileFileContents = GetFile(FileName)
'replace all string In the source
filedFileContents = replace(FileContents, Find, ReplaceWith, 1, -1, 1)
'Compare source And resultif dFileContents <> FileContents
Then'write result If different
WriteFile FileName, dFileContents
If Len(ReplaceWith) <> Len(Find) Then 'Can we
count n of replacements? fOut.WriteLine "DB " & FileName & "
file Fixed." fOut.WriteLine _ (
(Len(dFileContents) - Len(FileContents)) / (Len(ReplaceWith)-Len(Find)) ) &
_ " fixes Applied."End
IfElse ' fOut.WriteLine "No
Fixes Applied to source file " & FileNameEnd If
End Function'Read text file
function GetFile(FileName)
If FileName<>""
Then Dim FS, FileStream Set FS =
CreateObject("Scripting.FileSystemObject")on error resume Next
Set FileStream = FS.OpenTextFile(FileName)
GetFile = FileStream.ReadAll End IfEnd Function
'Write string As a text file.function WriteFile(FileName, Contents)
Dim OutStream, FS
on error resume NextSet FS = CreateObject("Scripting.FileSystemObject")
Set OutStream = FS.OpenTextFile(FileName, 2, True)
OutStream.Write Contents
End
Function Sub DoStuff(sDir,Find,ReplaceWith)
fOut.WriteLine sDirSet
oDir = oFSO.GetFolder(sDir)
For Each i In oDir.Filesf=Fix(i.Path, Find, ReplaceWith)Next
For Each i In oDir.SubFoldersDoStuff i.Path,Find,ReplaceWithNext
fOut.WriteLine ""'For Each i In oDir.SubFolders'DoStuff i.Path'
Next
End Sub
sabato 24 ottobre 2009
Massive string in file sustitution by vbs script
Massive string in file sustitution by vbs script :
Iscriviti a:
Commenti sul post (Atom)
Nessun commento:
Posta un commento