Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Loops 自动热键:复制不带路径和扩展名的文件名_Loops_Parameters_Path_Copy_Autohotkey - Fatal编程技术网

Loops 自动热键:复制不带路径和扩展名的文件名

Loops 自动热键:复制不带路径和扩展名的文件名,loops,parameters,path,copy,autohotkey,Loops,Parameters,Path,Copy,Autohotkey,欢迎大家 以下代码来自此处: 作者:奥德拉尼尔 q:: fileselected := Explorer_GetSelection() SplitPath,fileselected, fn MsgBox % "FileName :`t" fn "`nFullName :`t" fileselected clipboard = % "FileName :`t" fn "`nFullName :`t" fileselected return

欢迎大家

以下代码来自此处:

作者:奥德拉尼尔

        q::
    fileselected := Explorer_GetSelection()
    SplitPath,fileselected, fn
    MsgBox % "FileName :`t" fn "`nFullName :`t" fileselected
    clipboard = % "FileName :`t" fn "`nFullName :`t" fileselected
    return


    Explorer_GetSelection(hwnd="") {
        WinGet, process, processName, % "ahk_id" hwnd := hwnd? hwnd:WinExist("A")
        WinGetClass class, ahk_id %hwnd%
        if (process = "explorer.exe")
            if (class ~= "Progman|WorkerW") {
                ControlGet, files, List, Selected Col1, SysListView321, ahk_class %class%
                Loop, Parse, files, `n, `r
                ToReturn .= A_Desktop "\" A_LoopField "`n"
        } else if (class ~= "(Cabinet|Explore)WClass") {
            for window in ComObjCreate("Shell.Application").Windows
                if (window.hwnd==hwnd)
                    sel := window.Document.SelectedItems
            for item in sel
                ToReturn .= item.path "`n"
        }
    return Trim(ToReturn,"`n")


}
return
当您单击热键时,我们将获得所选文件的文件名和路径, 随附图片

我的问题是:如何仅按文件名获取列表,而不包含文件路径和文件扩展名 随附图片

非常感谢您的帮助。

新编辑的代码:

q::
fileselected := Explorer_GetSelection()
MsgBox % fileselected
clipboard = % fileselected
return


Explorer_GetSelection(hwnd="") {
    WinGet, process, processName, % "ahk_id" hwnd := hwnd? hwnd:WinExist("A")
    WinGetClass class, ahk_id %hwnd%
    if (process = "explorer.exe")
        if (class ~= "Progman|WorkerW") {
            ControlGet, files, List, Selected Col1, SysListView321, ahk_class %class%
            Loop, Parse, files, `n, `r
            ToReturn .= A_Desktop "\" A_LoopField "`n"
    } else if (class ~= "(Cabinet|Explore)WClass") {
        for window in ComObjCreate("Shell.Application").Windows
            if (window.hwnd==hwnd)
                sel := window.Document.SelectedItems
        for item in sel
            ToReturn .= item.path "`n"
    }
 fileselected:=ToReturn . "`n"
 while RegExMatch(fileselected,"s)\\(.*)")
 {
 RegExMatch(fileselected,"s)(.*?)(\n)",filestemp)
 RegExMatch(filestemp,"(.*)\.",filestemp)
  while RegExMatch(filestemp1,"s)\\(.*)")
   RegExMatch(filestemp1,"s)\\(.*)",filestemp)
 filesfin := filesfin . filestemp1 . "`n"
 RegExMatch(fileselected,"\n(.*)",filestemp)
 fileselected:=filestemp1
 }
 return (filesfin)


}
return

更简单的解决方案是只编辑一行:

SplitPath fileselected, fNameExt, fDir, fExt, fName, fDrv
然后以任何方式使用
fName
或任何其他结果

当然,您可以省略其他参数:

SplitPath fileselected,,,, fName

嗨,Roman,我丢失了代码中最重要的功能是处理任意数量的选定文件,现在代码只显示一个文件名。它不起作用。嗨,Roman,你为我节省了很多时间和精力。你真是太棒了。非常好的帮助,值得称赞的举措。谢谢你。我的帮助很好。我的第一个解决方案与此非常相似,但它没有正常工作,因为fName只返回第一个选定的文件,而fileselected返回所有文件。哦,你说得对,Roman。我错过了OP对你答案的评论。嗨,约翰利,谢谢你的积极性,你教了我一些新东西,非常感谢