FileSelect

ファイルを開く、または保存するための標準的なダイアログを表示します。

SelectedFile := FileSelect(Options, RootDir\Filename, Title, Filter)

パラメータ

Options

型:文字列または整数

省略したときは、初期設定は0となります。次のオプションが何も設定されないのと同じです。そうでなければ、数字または次の文字を指定します。文字の後に数字が組み合わされることもあります。例えば、"M"、"1"M1"はすべて有効です(ただし、同等ではありません)。

D: Select Folder (Directory). Dを指定すると、ファイルではなくフォルダーを選択できるようになります。このダイアログは、ファイルを選択するときとほぼ同じ機能を持ちますが、フィルターには対応していません(フィルターは省略されるか空白になります。)

M: Multi-select. Mを指定すると、シフトクリックコントロールクリックなどで複数のファイルを選択できるようになります。この場合、戻り値は文字列ではなく、配列になります。個々のファイルを取り出すには、このページ下部の例を参照してください。

S: Save dialog. Sを指定すると、ダイアログに常に「開く」ボタンの代わりに「保存」ボタンが表示されるようになります。

以下の数字を使用することができます。複数を有効にするには。、それらを足し算します。例えば、1と2を使う場合は、数字の3を指定します。

1: File Must Exist
2: Path Must Exist
8:新しいファイルを作成するかどうかを確認します。
16:ファイルを上書きするかどうか確認します。
32: Shortcuts (.lnk files) are selected as-is rather than being resolved to their targets. また、このオプションは、フォルダーショートカットによるフォルダーへのナビゲーションを防止します。

As the "Prompt to Overwrite" option is supported only by the Save dialog, specifying that option without the "Prompt to Create" option also puts the S option into effect. Similarly, the "Prompt to Create" option has no effect when the S option is present. 24を指定すると、ダイアログでサポートされているどのタイプのプロンプトも有効になります。

RootDir\Filename

型:文字列

If blank or omitted, the starting directory will be a default that might depend on the OS version (it will likely be the directory most recently selected by the user during a prior use of FileSelect). Otherwise, specify one or both of the following:

RootDir: The root (starting) directory, which is assumed to be a subfolder in A_WorkingDir if an absolute path is not specified.

Filename: The default filename to initially show in the dialog's edit field. 裸のファイル名(パスなし)のみが表示されます。To ensure that the dialog is properly shown, ensure that no illegal characters are present (such as /<|:").

例:

"C:\My Pictures\Default Image Name.gif"  ; RootDirFilenameの両方が存在します。
"C:\My Pictures"  ; RootDirのみ存在します。
"My Pictures"  ; RootDirのみが存在し、現在の作業ディレクトリからの相対パスです。
"My File"  ; Filenameのみ存在します(ただし、"My File"がフォルダとして存在する場合は、RootDirとします)。
タイトル

型:文字列

If blank or omitted, it defaults to "Select File - " A_ScriptName (i.e. the name of the current script), unless the "D" option is present, in which case the word "File" is replaced with "Folder". Otherwise, specify the title of the file-selection window.

Filter

型:文字列

If blank or omitted, the dialog will show all type of files and provide the "All Files (*.*)" option in the "Files of type" drop-down list.

Otherwise, specify a string to indicate which types of files are shown by the dialog, e.g. "Documents (*.txt)". To include more than one file extension in the filter, separate them with semicolons, e.g. "Audio (*.wav; *.mp2; *.mp3)". In this case, the "Files of type" drop-down list has the specified string and "All Files (*.*)" as options.

"D"オプションがある場合、このパラメータは空白または省略する必要があります。

戻り値

型:文字列または配列

マルチセレクトが有効でない場合、この関数は、ユーザーが選択した単一のファイルまたはフォルダのフルパスと名前を返し、ユーザーがダイアログをキャンセルした場合は空の文字列を返します。

Mオプション(複数選択)が有効な場合、この関数は項目の配列を返し、各項目は1つのファイルのフルパスと名前になります。本ページ下部の例では、ファイルを1つずつ抽出する方法を示しています。ユーザーがダイアログをキャンセルした場合、配列は空(アイテムがゼロ)になります。

備考

ファイル選択ダイアログは、通常このように表示されます:

FileSelect

GUIウィンドウは、+OwnDialogsオプションにより、モーダルファイル選択ダイアログを表示することができる。モーダルダイアログは、ダイアログが解除されるまで、ユーザーがGUIウィンドウと対話するのを防ぎます。

DirSelect, MsgBox, InputBox, ToolTip, GUI, CLSID List, parsing loop, SplitPath

また、OSには、フォント、色、アイコンの選択を促すダイアログボックスが標準装備されています。These dialogs can be displayed via DllCall in combination with comdlg32\ChooseFont, comdlg32\ChooseColor, or shell32\PickIconDlg. Search the forums for examples.

既存の.txtまたは.docファイルを選択できるようにします。

SelectedFile := FileSelect(3, , "Open a file", "Text Documents (*.txt; *.doc)")
if SelectedFile = ""
    MsgBox "The dialog was canceled."
else
    MsgBox "The following file was selected:`n" SelectedFile

既存のファイルを複数選択できるようにします。

SelectedFiles := FileSelect("M3")  ; M3 = 既存ファイルをマルチセレクトします。
if SelectedFiles.Length = 0
{
    MsgBox "The dialog was canceled."
    return
}
for FileName in SelectedFiles
{
    Result := MsgBox("File #" A_Index " of " SelectedFiles.Length ":`n" FileName "`n`nContinue?",, "YN")
    if Result = "No"
        break
}

フォルダーを選択できるようにします。

SelectedFolder := FileSelect("D", , "Select a folder")
if SelectedFolder = ""
    MsgBox "The dialog was canceled."
else
    MsgBox "The following folder was selected:`n" SelectedFolder