Autohotkey 按输入框搜索所有文件中的字符串

Autohotkey 按输入框搜索所有文件中的字符串,autohotkey,Autohotkey,此代码从此处开始: 此代码用于“在文件中搜索字符串” 文件:=“*.txt”;可以包含目录--*是通配符 StringCheck:=“字符串”;替换为搜索字符串 FileHit:=“”;空的 循环,%File%,1 { 文件读取,文件检查,%A\u LoopFileLongPath% i安装,文件检查,%StringCheck% FileHit%A_Index%:=A_LoopFileLongPath } 回路,100 { 如果(文件命中%A\u索引%“”) FileHit.=FileHit%A

此代码从此处开始:

此代码用于“在文件中搜索字符串”
文件:=“*.txt”;可以包含目录--*是通配符
StringCheck:=“字符串”;替换为搜索字符串
FileHit:=“”;空的
循环,%File%,1
{
文件读取,文件检查,%A\u LoopFileLongPath%
i安装,文件检查,%StringCheck%
FileHit%A_Index%:=A_LoopFileLongPath
}
回路,100
{
如果(文件命中%A\u索引%“”)
FileHit.=FileHit%A_Index%。“`n”
}
MsgBox,%FileHit

我的问题是: 代码是否可能由用户从inputbox获取字符串,并从对话框获取路径


如果有人能告诉我怎么做,我将非常感激

尝试在脚本中添加以下内容:

File := "*.txt"             ;can include directory -- * is wildcard
StringCheck := ""           ;replace with search string
FileHit := ""               ;empty

InputBox, Directory, Enter the searched directory, Leave empty to use the current directory. Subfolders will be also searched., , 300, 150
if ErrorLevel
{
    MsgBox, Query canceled.
    Exit
}

Directory := RegExReplace(Directory, "\\$") ; Removes the leading backslash, if present.

If Directory
{
    If(!InStr(FileExist(Directory), "D"))
    {
        msgbox Invalid directory
        Exit
    }
    StringRight, DirectoryEndingChar, Directory, 1
    If(DirectoryEndingChar != "\")
        Directory .= "\"
}

InputBox, StringCheck, Enter string to search, The search string is not case sensitive., , 300, 150

if ErrorLevel
{
    MsgBox, Query canceled.
    Exit
}

Loop, %Directory%%File%, , 1
{
   FileRead, FileCheck, %A_LoopFileLongPath%
   IfInString, FileCheck, %StringCheck%
      FileHit%A_Index% := A_LoopFileLongPath
}
Loop, 100
{
   If (FileHit%A_Index% <> "")
      FileHit .= FileHit%A_Index% . "`n"
}

If FileHit
    MsgBox, % FileHit
Else
    MsgBox, No match found.
文件:=“*.txt”;可以包含目录--*是通配符
StringCheck:=“”;替换为搜索字符串
FileHit:=“”;空的
输入框,目录,输入搜索的目录,留空使用当前目录。子文件夹也将被搜索。300150
如果错误级别
{
MsgBox,查询已取消。
出口
}
目录:=RegExReplace(目录“\\$”;删除前导反斜杠(如果存在)。
如果目录
{
如果(!InStr(文件存在(目录),“D”))
{
msgbox目录无效
出口
}
StringRight,目录EndingChar,目录,1
If(DirectoryEndingChar!=“\”)
目录。=“\”
}
InputBox,StringCheck,输入要搜索的字符串,搜索字符串不区分大小写,300150
如果错误级别
{
MsgBox,查询已取消。
出口
}
循环,%Directory%%文件%1
{
文件读取,文件检查,%A\u LoopFileLongPath%
i安装,文件检查,%StringCheck%
FileHit%A_Index%:=A_LoopFileLongPath
}
回路,100
{
如果(文件命中%A\u索引%“”)
FileHit.=FileHit%A_Index%。“`n”
}
如果文件命中
MsgBox,%FileHit
其他的
MsgBox,未找到匹配项。

我非常感谢您的帮助,非常感谢。很高兴我能帮忙。如果答案解决了问题,请将其标记为正确。劳尔·塞巴斯蒂安先生。我非常感谢你的帮助,非常感谢。
File := "*.txt"             ;can include directory -- * is wildcard
StringCheck := ""           ;replace with search string
FileHit := ""               ;empty

InputBox, Directory, Enter the searched directory, Leave empty to use the current directory. Subfolders will be also searched., , 300, 150
if ErrorLevel
{
    MsgBox, Query canceled.
    Exit
}

Directory := RegExReplace(Directory, "\\$") ; Removes the leading backslash, if present.

If Directory
{
    If(!InStr(FileExist(Directory), "D"))
    {
        msgbox Invalid directory
        Exit
    }
    StringRight, DirectoryEndingChar, Directory, 1
    If(DirectoryEndingChar != "\")
        Directory .= "\"
}

InputBox, StringCheck, Enter string to search, The search string is not case sensitive., , 300, 150

if ErrorLevel
{
    MsgBox, Query canceled.
    Exit
}

Loop, %Directory%%File%, , 1
{
   FileRead, FileCheck, %A_LoopFileLongPath%
   IfInString, FileCheck, %StringCheck%
      FileHit%A_Index% := A_LoopFileLongPath
}
Loop, 100
{
   If (FileHit%A_Index% <> "")
      FileHit .= FileHit%A_Index% . "`n"
}

If FileHit
    MsgBox, % FileHit
Else
    MsgBox, No match found.