我正在试图用下面的用例实现一个recursionsearch脚本: –
我用批处理脚本试了一下,试图从html页面运行参数(string和目录)。 它失败了, 因为提到了stackoverflow (由于javascripts无法访问文件系统)。
我的批处理脚本是: findstr /s /i /n /C:@name= *.* v > results.txt
现在我想知道如果我的要求可以用batch file来实现,或者我需要切换到VBScript。 请build议。 我没有vbscript的想法。
我无法在我的Windows工作站上安装任何第三方工具。
这是vbscript,如果从本地页面运行,将不会触发安全对话框。
On Error Resume Next Set fso = CreateObject("Scripting.FileSystemObject") Dirname = InputBox("Enter Dir name") Searchterm = Inputbox("Enter search term") ProcessFolder DirName Sub ProcessFolder(FolderPath) Set fldr = fso.GetFolder(FolderPath) Set Fls = fldr.files For Each thing in Fls Set contents = thing.OpenAsTextStream If Instr(contents.readall, searchterm) then wscript.echo thing.path Next Set fldrs = fldr.subfolders For Each thing in fldrs ' wscript.echo thing.name ProcessFolder thing.path Next End Sub
编辑和编辑2 (添加浏览文件夹)
在HTA(我不得不从头开始 – 我不能让你的屠杀我的脚本工作)。
<HTML> <HEAD><TITLE>Simple Validation</TITLE> <SCRIPT LANGUAGE="VBScript"> Dim Dirname Dim Searchterm Dim FSO Dim objOutFile Sub Browse On Error Resume Next Set bffShell = CreateObject("Shell.Application") Set bff = bffShell.BrowseForFolder(0, "Select the My Documents folder", 9) If Err.number<>0 Then MsgBox "Error Setting up Browse for Folder" Else A = bff.ParentFolder.ParseName(bff.Title).Path If err.number=424 then err.clear tb2.value = A End If End Sub Sub Search On Error Resume Next Set fso = CreateObject("Scripting.FileSystemObject") Set objOutFile = fso.CreateTextFile("results.txt",True) Dirname = tb2.value Searchterm = tb1.value ProcessFolder DirName End Sub Sub ProcessFolder(FolderPath) On Error Resume Next Set fldr = fso.GetFolder(FolderPath) Set Fls = fldr.files For Each thing in Fls Set contents = thing.OpenAsTextStream If err.number = 0 then Test = Instr(contents.readall, searchterm) If Isnull(test) = false then If Test > 0 then ObjOutFile.WriteLine thing.path Else err.clear End If Next Set fldrs = fldr.subfolders For Each thing in fldrs ProcessFolder thing.path Next End Sub </script> </head> <body> <p><INPUT Name=tb1 TYPE=Text Value="Search"> <p><INPUT Name=tb2 TYPE=Text Value="Folder"> <INPUT NAME="Browse" TYPE="BUTTON" VALUE="Browse" OnClick=Browse> <p><INPUT NAME="Search" TYPE="BUTTON" VALUE="Search" OnClick=Search> </body> </html>