VBS 显示“选择文件或文件夹”对话框的代码

2019-01-16 00:49:18刘景俊

  当然可以。我们不详述这个修改后的脚本,但该脚本会将“我的电脑”设置为根文件夹:
    


Const MY_COMPUTER = &H11&
    Const WINDOW_HANDLE = 0
    Const OPTIONS = 0
    Set objShell = CreateObject("Shell.Application")
    Set objFolder = objShell.Namespace(MY_COMPUTER)
    Set objFolderItem = objFolder.Self
    strPath = objFolderItem.Path
    Set objShell = CreateObject("Shell.Application")
    Set objFolder = objShell.BrowseForFolder _
    (WINDOW_HANDLE, "Select a folder:", OPTIONS, strPath)
    If objFolder Is Nothing Then
    Wscript.Quit
    End If
    Set objFolderItem = objFolder.Self
    objPath = objFolderItem.Path
    Wscript.Echo objPath

  如您所料,所得到的对话框提供了很多选择。这正是您所需要的。