You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

AutoHotkey实现复制不含路径与扩展名的文件名

提取资源管理器选中文件信息的AutoHotkey脚本

给大家分享一个实用的AutoHotkey小脚本,按下快捷键q就能快速获取资源管理器中选中文件的关键信息:

  • 提取不含路径与扩展名的纯文件名
  • 弹出提示框展示文件名和完整路径
  • 自动把这些信息复制到剪贴板,方便后续使用

这个脚本由Odlanir编写,完整代码如下:

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")
}

脚本功能拆解

  • q:::设置触发快捷键为q,在资源管理器窗口按下即可执行
  • Explorer_GetSelection():自定义函数,负责获取当前资源管理器窗口中选中的文件路径
  • SplitPath, fileselected, fn:拆分文件路径,提取出纯文件名(不含路径和扩展名)存入变量fn
  • MsgBox:弹出提示框,清晰展示文件名和完整路径
  • clipboard = ...:将展示的信息复制到系统剪贴板,直接粘贴就能使用

内容的提问来源于stack exchange,提问作者asad41163

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 07:45:41