在我的程序中,我想创建一个带有基于文件夹及其子文件夹的子菜单的菜单。
第一个功能menu_fromfiles
工作正常。
但是第二个函数menu_fromfolders
一直给我一个错误:submenu does not exist
- 我无法弄清楚。有什么线索吗?
这是我的代码:
#SingleInstance force
RButton::
menu_fromfolders("filelist", "File List", "c:\test", "*.txt", "thismenu")
menu, thismenu, show
Return
-------------------------------------------------------------------
menu_fromfolders(submenuname, menutitle, whatdir, filemask="*", parentmenu="", whatsub="DONOTATHING"){
global
loop, %whatdir%\*, 1, 0
{
if(file_isfolder(A_LoopFileFullPath)){
menu_fromfiles(a_loopfilename, a_loopfilename, A_LoopFileFullPath, filemask, "", whatsub)
menu, %submenuname%, add, %a_loopfilename%, :%a_loopfilename%
}else{
menu, %submenuname%, add, %a_loopfilename%, %whatsub%
}
}
if(parentmenu){
menu, %parentmenu%, add, %menutitle%, :%submenuname%
}
return submenuname
}
menu_fromfiles(submenuname, menutitle, whatdir, filemask="*", parentmenu="", whatsub="DONOTATHING"){
loop, %whatdir%\%filemask%, 0, 0
{
menu, %submenuname%, add, %a_loopfilename%, %whatsub%
}
if(parentmenu){
menu, %parentmenu%, add, %menutitle%, :%submenuname%
}
return submenuname
}
;returns true if the item is a folder, false if is a file
file_isfolder(whatfile){
lastchar := substr(whatfile, 0, 1) ;fetch the last character from the string
if(lastchar != "\")
whatfile := whatfile . "\"
if(fileexist(whatfile))
return true
}
;empty command for the menu title
DONOTATHING:
return
这是更详细的错误消息:
Error in ...script.ahk
Submenu does not exist
-->menu, %submenuname%, add, %a_loopfilename%, :%a_loopfilename%
[更新]
请在下面查看我的解决方案。你可以在这里找到完整和完善的脚本:http ://www.autohotkey.com/board/topic/95219-dynamicfilemenuahk/