autohotkey:复制没有路径和扩展名的文件名
autohotkey: copy file name without Path and Extension
欢迎大家
以下代码来自此处:https://autohotkey.com/boards/viewtopic.php?f=5&t=44848
作者: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")
}
return
当您点击热键时,我们会得到所选文件的文件名和路径,
如图所示
https://drive.google.com/open?id=1VvPKYrbVQEfrmdB34dUND9HbnXMl0Lr2
我的问题是:如何仅按文件名获取列表,不带文件路径和文件扩展名
如图所示
https://drive.google.com/open?id=1rCuLikjqT8Nudipby5Y9MOHTqdozGPYn
如有任何帮助,我们将不胜感激。
新编辑的代码:
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
欢迎大家
以下代码来自此处:https://autohotkey.com/boards/viewtopic.php?f=5&t=44848
作者: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")
}
return
当您点击热键时,我们会得到所选文件的文件名和路径, 如图所示
https://drive.google.com/open?id=1VvPKYrbVQEfrmdB34dUND9HbnXMl0Lr2
我的问题是:如何仅按文件名获取列表,不带文件路径和文件扩展名 如图所示
https://drive.google.com/open?id=1rCuLikjqT8Nudipby5Y9MOHTqdozGPYn
如有任何帮助,我们将不胜感激。
新编辑的代码:
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