Hello Steve Holle,
maybe your not strong enough to write a script in VBS or JS so I try a little
bit to help you (because I am busy).
The following script searchs all files in a specific folder and write them to a
file. Maybe you analyse it and modify a Script which you save in
Pspad-Directory\Script\VBScript and activate WSH-scripting in the main options?
(Because the script is very large I am writing my suggestions here:
maybe I give you a PSPad version in a Future-Release in this section if your
interrested, other wise I should sold money for this:-D):
'Dateiname: SearchinDir.vbs
'Autor: Holger
'Parameter:
'1. Folder to search in
'2. Extensions (Commaseparated)
'3. Textsearch true/false
'4. Text when 3.
'5. Replace true/false
'6. Replacetext when 5.
'7. Autoreplace true/false falls 5.
'No Parameter:
' the Script Remarks for Folders and Files in the Kontextmenue!
'Initialisations
'SYS: Microsoft (r) Script Runtime
Set fs = CreateObject("Scripting.FileSystemObject")
'SYS: Windows Script Host Runtime Library
Set wshshell = CreateObject("WScript.Shell")
'Temporary Folder
Set Tempfolder = fs.GetSpecialFolder(2)
lSearch = false
lReplace = false
lDiffFiles = false
DiffFiles = ""
TempDirname = TempFolder.Path & "\TempDirs.txt"
TempDirSub = TempFolder.Path & "\TempSub.txt"
AllFilename = TempFolder.Path & "\AllFiles.txt"
AllDirname = TempFolder.Path & "\AllDirs.txt"
LogFilename = TempFolder.Path & "\LogFiles.csv"
If fs.FileExists(LogFilename) Then
fs.DeleteFile(LogFilename)
End If
If fs.FileExists(TempDirSub) Then
fs.DeleteFile(TempDirSub)
End If
If fs.FileExists(TempDirname) Then
fs.DeleteFile(TempDirname)
End If
If fs.FileExists(AllFilename) Then
fs.DeleteFile(AllFilename)
End If
If fs.FileExists(AllDirname) Then
fs.DeleteFile(AllDirname)
End If
'Parameters
Set args = WScript.Arguments
'Parameter based Settings
If args.Count = 0 Then
Key = "HKCR\Directory\shell\PSearch\"
wshshell.RegWrite Key, "Inhalt Protokollieren"
wshshell.RegWrite Key & "command\", "wscript.exe """ & WScript.ScriptFullName
& """ ""%L"""
Key = "HKCR\Drive\shell\PSearch\"
wshshell.RegWrite Key, "Inhalt Protokollieren"
wshshell.RegWrite Key & "command\", "wscript.exe """ & WScript.ScriptFullName
& """ ""%L"""
WScript.Quit
ElseIf Not fs.FolderExists(args(0)) Then
MsgBox "The Drive or Folder " & vbCr & args(0) & vbCr & "could not found!"
WScript.Quit
End If
Set Folder = fs.GetFolder(args(0))
Dir = Folder.Path
If args.count > 1 Then
If args(1) <> "" Then
lDiffFiles = true
DiffFiles = args(1)
FileArray = Split(DiffFiles,",",-1)
Else
DiffFiles = InputBox("Please define commaseparated the extensions to search
for","Extensionsdefinition")
If DiffFiles <> "" Then
FileArray = Split(DiffFiles,",",-1)
lDiffFiles = true
End If
End If
End If
If args.Count > 2 Then
If args(2) = "true" Then
lSearch = true
Else
lSearch = false
End If
If args(2) = "true" Then
If args.Count < 4 Then
Search = InputBox("Search-Value (if empty only
Protocoll)","Search-Value")
If Search = "" Then
lSearch = false
End If
Else
Search = args(3)
End If
End If
End If
If args.Count > 4 Then
If args(4) = "true" Then
lValue = true
Else
lValue = false
End If
If args(4) = "true" Then
Value = ""
If args.Count < 6 Then
Value = InputBox("Replace-Value","Replace with")
Else
Value = args(5)
End If
if args.Count < 7 Then
iReturn = MsgBox("Replace everything in Directory?",36,"Choose
Replacemode")
If iReturn = 6 Then
lReplace = true
Else
lReplace = false
End If
Else
If args(6) = "true" Then
lReplace = true
Else
lReplace = false
End If
End If
End If
End If
'Read Root
GetSub(Dir)
If fs.FileExists(TempDirSub) Then
Set NewFile = fs.GetFile(TempDirSub)
NewFile.Move(TempDirname)
End If
If fs.FileExists(TempDirname) Then
On Error Resume Next
Set Tmptext = fs.OpenTextFile(TempDirname, 1, true)
OK = (Err.Number = 0)
If OK Then
On Error GoTo 0
Else
WScript.Quit
End If
Else
WScript.Quit
End If
'Read SubFolders
Do While Not Tmptext.AtEndOfStream
GetSub(Tmptext.ReadLine)
If Tmptext.AtEndOfStream Then
Tmptext.Close
Set File = fs.GetFile(TempDirname)
File.Delete(true)
For i = 1 To 10000
Next
If fs.FileExists(TempDirSub) Then
Set NewFile = fs.GetFile(TempDirSub)
NewFile.Move(TempDirname)
End If
If fs.FileExists(TempDirname) Then
On Error Resume Next
Set Tmptext = fs.OpenTextFile(TempDirname, 1, true)
OK = (Err.Number = 0)
If OK Then
On Error GoTo 0
Else
Exit Do
End If
Else
Exit Do
End If
End If
Loop
For i = 0 to 10000
Next
'Show Results if you want
If fs.FileExists(AllFilename) Then
' wshshell.run AllFilename
End If
If fs.FileExists(AllDirname) Then
' wshshell.run AllDirname
End If
if lSearch = true AND fs.FileExists(LogFilename) Then
' wshshell.run LogFilename
End If
'release Objects
set args = nothing
set wshshell = nothing
set fs = nothing
set Folder = nothing
set LogFiles = nothing
set TempFolder = nothing
set AllFiles = nothing
set Filename = nothing
WScript.Quit
'End Procedure
'Subprocedures
Sub GetSub(ReadDir)
If fs.FolderExists(ReadDir) Then
Set Folder = fs.GetFolder(ReadDir)
For each Directory in Folder.SubFolders
On Error Resume Next
Set Temptext = fs.OpenTextFile(TempDirSub, 8, true)
OK = (Err.Number = 0)
If OK Then
On Error GoTo 0
Temptext.WriteLine Directory.Path
Temptext.Close
End If
On Error Resume Next
Set Dirtext = fs.OpenTextFile(AllDirname, 8, true)
OK = (Err.Number = 0)
If OK Then
On Error GoTo 0
Dirtext.WriteLine Directory.Path
Dirtext.Close
End If
Next
On Error Resume Next
Set Temptext = fs.OpenTextFile(TempDirSub, 8, true)
OK = (Err.Number = 0)
If OK Then
On Error GoTo 0
Temptext.WriteBlankLines(1)
Temptext.Close
End If
For each file in Folder.Files
On Error Resume Next
Set Filetext = fs.OpenTextFile(AllFilename, 8, true)
OK = (Err.Number = 0)
If OK Then
On Error GoTo 0
If lDiffFiles = true Then
For each Difffile in FileArray
If InStr(LCase(file.Path),LCase(Difffile)) > 0 Then
Filetext.WriteLine file.Path
If lSearch = true Then
Set LogFiles = fs.OpenTextFile(LogFilename, 8, true)
ActFile = file.Path
Set Filename = fs.OpenTextFile(ActFile, 1, true)
if lValue = true Then
TempArea = ActFile & ".tmp"
Set ReplFile = fs.OpenTextFile(TempArea, 8, true)
End If
Do While Not Filename.AtEndOfStream
if lValue = true Then
Replstring = Filename.ReadLine
If InStr(Replstring,Search) > 0 Then
If LReplace = true Then
LogFiles.Writeline ActFile & ";" & Filename.Line - 1 &
";" & ReplString
ReplString = Replace(Replstring,Search,Value)
Else
Return = MsgBox("Should the Entry " & Search & " in Line
" & Filename.Line - 1 & " of File " & ActFile & " be replaced?",36,"Replace")
If Return = 6 Then
LogFiles.Writeline ActFile & ";" & Filename.Line - 1 &
";" & ReplString
ReplString = Replace(Replstring,Search,Value)
End If
End If
End If
ReplFile.Writeline ReplString
Else
Logstring = Filename.ReadLine
If InStr(Logstring,Search) > 0 Then
LogFiles.Writeline ActFile & ";" & Filename.Line - 1 & ";"
& Logstring
End If
End If
Loop
Filename.Close
LogFiles.Close
if lValue = true Then
ReplFile.Close
Set Filename = fs.OpenTextFile(ActFile, 2, true)
Set ReplFile = fs.OpenTextFile(TempArea, 1, true)
Do While Not ReplFile.AtEndOfStream
Filename.Writeline ReplFile.ReadLine
Loop
Filename.Close
ReplFile.Close
For i = 1 To 10000
Next
fs.DeleteFile(TempArea)
For i = 1 To 10000
Next
End If
End If
End If
Next
Else
Filetext.WriteLine file.Path
If lSearch = true Then
Set LogFiles = fs.OpenTextFile(LogFilename, 8, true)
ActFile = file.Path
Set Filename = fs.OpenTextFile(ActFile, 1, true)
if lValue = true Then
TempArea = ActFile & ".tmp"
Set ReplFile = fs.OpenTextFile(TempArea, 8, true)
End If
Do While Not Filename.AtEndOfStream
if lValue = true Then
Replstring = Filename.ReadLine
If InStr(Replstring,Search) > 0 Then
If LReplace = true Then
LogFiles.Writeline ActFile & ";" & Filename.Line - 1 & ";" &
ReplString
ReplString = Replace(Replstring,Search,Value)
Else
Return = MsgBox("Sollen die Einträge " & Search & " in der
Zeile " & Filename.Line - 1 & " der Datei " & ActFile & " ersetzt
werden?",36,"Ersetzen")
If Return = 6 Then
LogFiles.Writeline ActFile & ";" & Filename.Line - 1 & ";"
& ReplString
ReplString = Replace(Replstring,Search,Value)
End If
End If
End If
ReplFile.Writeline ReplString
Else
Logstring = Filename.ReadLine
If InStr(Logstring,Search) > 0 Then
LogFiles.Writeline ActFile & ";" & Filename.Line - 1 & ";" &
Logstring
End If
End If
Loop
Filename.Close
LogFiles.Close
if lValue = true Then
ReplFile.Close
Set Filename = fs.OpenTextFile(ActFile, 2, true)
Set ReplFile = fs.OpenTextFile(TempArea, 1, true)
Do While Not ReplFile.AtEndOfStream
Filename.Writeline ReplFile.ReadLine
Loop
Filename.Close
ReplFile.Close
For i = 1 To 10000
Next
fs.DeleteFile(TempArea)
For i = 1 To 10000
Next
End If
End If
End If
Filetext.Close
End If
Next
End If
End
--
<http://forum.pspad.com/read.php?2,40224,40241>
PSPad freeware editor http://www.pspad.com