FileOpenDialog

首页  后退  前进

FileOpenDialog
down2

FileOpenDialog

启动打开文件对话框.

 

FileOpenDialog ( "title", "init dir", "filter" [, options = 0 [, "default name" [, hwnd]]] )

参数

title

对话框窗口的标题

init dir

对话框窗口文件树的初始目录

filter

文件类型筛选. 例如: "全部 (*.*)" 或 "文本文件 (*.txt)";

或多重筛选, 例如: "全部 (*.*)|文本文件 (*.txt)" (见备注)

options

[可选] 对话框选项, 若多个选项, 使用 BitOR 连接所需的值.

   $FD_FILEMUSTEXIST (1) = 如果用户键入文件名, 则目标文件必须存在

   $FD_PATHMUSTEXIST (2) = 如果用户键入路径, 则路径必须存在且以反斜杠结尾

   $FD_MULTISELECT (4) = 允许选择多个文件

   $FD_PROMPTCREATENEW (8) = 如果文件不存在, 则提示用户创建新文件

 

常量定义在 FileConstants.au3

default name

[可选] 提示可打开的文件名. 默认为空 ("")

hwnd

[可选] 对话框的父窗口句柄

返回值

成功:

返回选中文件的完整路径. 多选则返回: "目录|文件1|文件2|..."

失败:

@error 设置 为非 0 值.

@error:

1 - 文件选择失败.

2 - 无效的文件类型筛选

备注

如示例所示的筛选, 使用分号分隔文件.

多筛选请使用管道符 "|" 分隔.

 

如果指定"默认文件名"参数, 则"选项"参数也必须指定. 如果不需要指定选项, 则设置"选项"参数为 0.

 

Windows 的特殊文件夹(如 "我的文档")也可以作为初始目录使用,详情请查看 附录.

 

成功的返回会改变 @WorkingDir 的值.

 

函数示例

示例 1

#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
Example()
Func Example()
    ; Create a constant variable in Local scope of the message to display in FileOpenDialog.
    Local Const $sMessage = "Hold down Ctrl or Shift to choose multiple files."
    ; Display an open dialog to select a list of file(s).
    Local $sFileOpenDialog = FileOpenDialog($sMessage, @WindowsDir & "\", "Images (*.jpg;*.bmp)|Videos (*.avi;*.mpg)", $FD_FILEMUSTEXIST + $FD_MULTISELECT)
    If @error Then
        ; Display the error message.
        MsgBox($MB_SYSTEMMODAL, "", "No file(s) were selected.")
        ; Change the working directory (@WorkingDir) back to the location of the script directory as FileOpenDialog sets it to the last accessed folder.
        FileChangeDir(@ScriptDir)
    Else
        ; Change the working directory (@WorkingDir) back to the location of the script directory as FileOpenDialog sets it to the last accessed folder.
        FileChangeDir(@ScriptDir)
        ; Replace instances of "|" with @CRLF in the string returned by FileOpenDialog.
        $sFileOpenDialog = StringReplace($sFileOpenDialog, "|", @CRLF)
        ; Display the list of selected files.
        MsgBox($MB_SYSTEMMODAL, "", "You chose the following files:" & @CRLF & $sFileOpenDialog)
    EndIf
EndFunc   ;==>Example

示例 2

#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
Example()
Func Example()
    ; Create a constant variable in Local scope of the message to display in FileOpenDialog.
    Local Const $sMessage = "Select a single file of any type."
    ; Display an open dialog to select a file.
    Local $sFileOpenDialog = FileOpenDialog($sMessage, @WindowsDir & "\", "All (*.*)", $FD_FILEMUSTEXIST)
    If @error Then
        ; Display the error message.
        MsgBox($MB_SYSTEMMODAL, "", "No file was selected.")
        ; Change the working directory (@WorkingDir) back to the location of the script directory as FileOpenDialog sets it to the last accessed folder.
        FileChangeDir(@ScriptDir)
    Else
        ; Change the working directory (@WorkingDir) back to the location of the script directory as FileOpenDialog sets it to the last accessed folder.
        FileChangeDir(@ScriptDir)
        ; Replace instances of "|" with @CRLF in the string returned by FileOpenDialog.
        $sFileOpenDialog = StringReplace($sFileOpenDialog, "|", @CRLF)
        ; Display the selected file.
        MsgBox($MB_SYSTEMMODAL, "", "You chose the following file:" & @CRLF & $sFileOpenDialog)
    EndIf
EndFunc   ;==>Example

----------------------------------------

 

该函数可以通过命令 exect 调用

参见:

FileSaveDialog, FileSelectFolder

例子
copy

exect=$var_s=FileOpenDialog('Выберите~~имя.','::{450D8FBA-AD25-11D0-98A8-0800361B1103}','Скрипт(*.aut;*.au3)|Текстовый~~файл(*.ini;*.txt)',2)||Eval('var_s')?_ViewValues('$var_s'):_Exit() ;; 显示打开的文件对话框。如果未选择,则输出

 

exect=$var_put=FileOpenDialog('Select~~the~~file~~to~~create~~a~~shortcut','::{450D8FBA-AD25-11D0-98A8-0800361B1103}','File~~Wallet(*.exe)',2)||_ViewValues('$var_put')||$var_put=$var_put=''?_Exit():$var_put||_ViewValues('$var_put') ;;显示打开的文件对话框。如果未选择,则输出

up2

tcimage © Аверин Андрей для Total Commander Image Averin-And@yandex.ru