FileDlgShow Returns Wrong Order of File Selection

Updated Aug 7, 2019

Reported In


  • DIAdem Professional
  • DIAdem Advanced
  • DIAdem Base

Issue Details

I am creating a Script in DIAdem that opens the file selection window by calling FileDlgShow . I select multiple files by holding the control key. Afterwards I want to work with the files by reading the variable FileDlgNameList, which contains the selected files:
Dim iCount
Call FileDlgShow(DataReadPath, "DAT Files,*.dat|TDM Files,*.tdm|Excel Files, *.csv;*.xls", "Data selection", True)    
For iCount = 0 To Ubound(FileDlgNameList)
  Call DataFileLoad(FileDlgNameList(iCount))

I noticed that the order of the files in FileDlgNameList differs from my order of selection: the first file I selected is the last element stored in the result list. The list begins with the second selected file.

For example the script above returns messageboxes in the following order: 
  1. C:\Users\[...]\file2.tdm
  2. C:\Users\[...]\file3.tdm
  3. C:\Users\[...]\file1.tdm
However I selected file1.tdm first and selected file2.tdm and file3.tdm afterwards.

How can I get the correct order of my file selection with FileDlgNameList?


By calling FileDlgShow DIAdem calls a Windows function that returns the user selection and DIAdem stores that result in FileDlgNameList. DIAdem has no influence on the way how and in which order the file selection will be returned by Windows.

Alternatives to work with the correct order files:
  • If your intention is to select all the files of the same file type inside one folder, you can use the function PathDlgShow to get the folder path through a dialogue window. Then you can use the OutPutPath Parameter as input to the DirListGet function to get a sorted list of filenames. The function itself has several options for filtering files and generating a sorted file list output. The following shows one way of implementation:
Dim sFolderList, iCount
Call PathDlgShow("Please select folder", DataReadPath) 
sFolderList = DirListGet(OutPutPath, "*.tdm", "filename", "FullFilenames") 
For iCount = 0 To Ubound(sFolderList)
  Call DataFileLoad(sFolderList(iCount))
  • Before iterating through the list of files in FileDlgNameList pick the last element of FileDlgNameList that is actually the first one with the UBound function: FileDlgNameList(Ubound(FileDlgNameList))
  • In case your selection matches an alphabetical or numerical order you can sort FileDlgNameList. Other users already posted their approach of sorting in the NI forum.