shell 资源管理器“浏览文件夹”

6ovsh4lw  于 2023-04-12  发布在  Shell
关注(0)|答案(1)|浏览(179)

我试图创建一个脚本,需要用户为他们的项目选择起始文件夹。我已经找到了几个源代码,但编码语言不是我使用的。我使用的语言是Autolisp,它很可能会调用shell应用程序来打开所需的GUI。

此外,还有Lee Mac创建的代码,它很接近,但它使用了一个对话框,如果给定了起始目录,则限制用户访问父目录:Browse for Folder
有没有一种方法可以打开“选择文件夹”GUI,如下图所示,最好使用AutoLisp?

j91ykkif

j91ykkif1#

我熟悉的唯一其他方法(除了利用Windows Shell对象的BrowseForFolder方法- per this example)以及暴露于ActiveX的方法是利用MS Office File Dialog对象,例如:

;; File Dialog  -  Lee Mac
;; Leverages the MS Office File Dialog object to present a dialog to the user
;; msg - [str] Dialog title ("" for default)
;; btn - [str] Button name  ("" for default)
;; ini - [str] Initial filename/directory
;; typ - [int] MsoFileDialogType (1-4)
;; mtp - [bol] Allow multiple selection (:vlax-true/:vlax-false)

(defun LM:filedialog ( msg btn ini typ mtp / dlg rtn xla )
    (if (setq xla (vlax-create-object "excel.application"))
        (progn
            (setq rtn
                (vl-catch-all-apply
                    (function
                        (lambda ( / tmp )
                            (setq dlg (vlax-get-property xla 'filedialog typ))
                            (vlax-put-property dlg 'title msg)
                            (vlax-put-property dlg 'buttonname btn)
                            (vlax-put-property dlg 'initialfilename ini)
                            (vlax-put-property dlg 'allowmultiselect mtp)
                            (vlax-put-property xla 'visible :vlax-true)
                            (if (= -1 (vlax-invoke-method dlg 'show))
                                (vlax-for itm (vlax-get-property dlg 'selecteditems)
                                    (setq tmp (cons itm tmp))
                                )
                            )
                        )
                    )
                )
            )
            (if dlg (vlax-release-object dlg))
            (if xla (vlax-release-object xla))
            (if (vl-catch-all-error-p rtn)
                (prompt (vl-catch-all-error-message rtn))
                rtn
            )
        )
    )
)

示例

(LM:filedialog "Select a Folder" "Select Folder" "" 4 :vlax-false)

然而,由于使用从MS Office应用对象导出的方法来调用对话框,因此这需要示例化所述应用对象,并且因此显然不是完全干净的结果。

相关问题