以下のコードで複数ファイルの選択が出来ない.
ロングファイルネームを使用しなければ複数選択が可能である.
Function SelectedFiles() as string
Dim flg
flg = cdlOFNHideReadOnly 'ReadOnlyを表示させない
flg = flg + cdlOFNLongNames 'ロングファイルをサポート
flg = flg + cdlOFNExplorer 'エクスプローラ風にする
flg = flg + cdlOFNAllowMultiselect '複数選択を可能にする
flg = flg + cdlOFNFileMustExist '存在するファイルのみ選択可能
With Screen.ActiveForm.cdlfileopen
.CancelError = True
.DialogTitle = "ファイルを選択"
.Flags = flg
End With
On Error Resume Next
Screen.ActiveForm.cdlfileopen.ShowOpen
If Err <> cdlCancel Then
SelectedFiles = Screen.ActiveForm.cdlfileopen.filename
End If
end function
C:\Program Files で a.txt b.txt の2つのファイルを選択しても C:\Program Files しか返らない.
これはファイル名の取得方法にコツが必要である.
デバッグウィンドウで見ると,SelectedFiles と Instr(SelectedFiles,Chr(0)) の値は,
SelectedFiles C:\Program Files a.txt b.txt
Instr(SelectedFiles,Chr(0)) 16
となる.
つまり NULL がターミネータとして付加されているのである.
NULL を除去して SelectedFiles を加工する必要がある.
参照