'1. In the module ModDlgSelectFileInfo .Option Explicit' function comprising: GetDlgSelectFileInfo 'Function: acquiring file information selected from the CommonDialog' self-defined types, functions for DlgSelectFileInfo Type DlgFileInfo iCount As Long sPath As String sFile () As StringEnd Type 'Features: Returns the number of files selected by Commondialog and file name' parameter description: StrfileName is a Commondialog.FileName 'function type: DLGFileInfo. This is a custom type, which is as follows: 'Type Dlgfileinfo' iCount As long 'spath as string' sfile () AS string 'end type' where ICOUNT is the number of files, spath is the path of the selected file, sfile ) For the selected file name '' Notes: Use after Commondialog.Showopen, so as to avoid the current path to be changed 'After opening the * .pif file, you must set the filename property empty, otherwise it is elected to multiple * .pif files The current path will change the use of the CDLOFNNODEREFERENCELINKS style in the CommondiaLong.Flags property, you can return the file name of the * .pif file correctly.
Public function getdlgselectfileinfo (StrfileName As String) AS DLGFILEINFO 'Idea: After selecting the file with the Commondialog control, its filename property value is as follows:' 1, if selected is "c: /test.txt", filename = "C: / Test. TXT ", curdir () =" c: / "'2, if selected" c: /1/test.txt ", filename =" c: /1/test.txt ", curdir () =" C: / 1 "'3, if" c: /1.txt "and" c: /2.txt "are selected,' filename =" c: / 1 1.txt 2.txt ", curdir () = "C: / 1" 'thus first separates the path, and then decomposes the names of each file with the CHR $ (0) character inserted between multi-files.
DIM SPATH, TMPSTR AS STRING DIM SFILE () AS STRING DIM ICOUNT AS INTEGER DIM I AS INTEGER ON ERROR GOTO ERRHANDLE SPATH = CURDIR () 'Gets the current path, because the current path TMPSTR = Right is changed when changing the path in Commondialog $ (strfilename, len (strfilename) - Len (spath) 'Separates the file name IF LEFT $ (Tmpstr, 1) = chr $ (0) TEN' Choosing multiple files (character is the first character to space ) For i = 1 To Len (tmpstr) IF $ (tmpstr, i, 1) = chr $ (0) Then iCount = iCount 1 redim preserve sfile (iCount) else sfile (iCount) = sfile (iCount) & MID $ (Tmpstr, I, 1) end if next i else 'only selected a file (note: the file name under the root directory is not "/") iCount = 1 Redim Preserve Sfile (ICOUNT) IFT $ (TmpStr) , 1) = "/" THEN TMPSTR = Right $ (Tmpstr, LEN (Tmpstr) - 1) sfile (iCount) = tmpstr endiff = iCount Redim getdlgselectfileinfo.sfile (iCount) if Right $ (Spath, 1) <> / "Then spath = spath &" getdlgselectfilei Nfo.spath = spath for i = 1 to icount getdlgselectfileinfo.sfile (i) = sfile (i) Next I exit functionerrhandle: msgbox "getdlgselectfileinfo function execution error! ", Vbokonly Vbcritical," Custom Function Error "
END FUNCTION