DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

scripting: browse for data files in a folder and all subfolders below

Hello,

 

i'm looking for a command to search for data files (*.dat) in a folder and all subfolders below.

 

I checked out command DirListGet. This command only search in the declared folder and not in the subfolders below.

 

Anyone an idea?

 

I don't want to use a loop-structure for finding subfolders and browse for the data files.

 

Mr. Buddy

0 Kudos
Message 1 of 5
(7,083 Views)

Hi,

if the files you are searching for are contained in a search area of the DataFinder, you can use the following script to find the files. The DataFinder is installed by default with DIAdem.

 

Dim DataFinder : Set DataFinder = Navigator.ConnectDataFinder("My DataFinder")
Dim Query : Set Query = DataFinder.CreateQuery(eAdvancedQuery)
Call Query.Conditions.Add(eSearchFile, "folder", "=", "C:\Program Files\National Instruments\DIAdem 2011\Examples\Data\*")
Call Query.Conditions.Add(eSearchFile, "fileName", "=", "*.tdm")
DataFinder.Search(Query)

Dim File
For each File in DataFinder.Results
  MsgBox(File.Properties("fullpath").Value)
Next

 

 

0 Kudos
Message 2 of 5
(7,080 Views)

I missed the fourth parameter of the command DirListGet. If you use "FullFilenamesRecursive", the command will search all subfolders and return the fullpath of the files found.

0 Kudos
Message 3 of 5
(7,078 Views)

It doesn't work.

changing the fourth parameter of "DirListGet" to "FullFilenamesRecursive" only changes the listing order to recursive with FullFilenames.

 

to add the data to mydatafinder takes just a long.

 

I'm looking for a simple way to include the data, like "DirListGet", but with including subfolders

0 Kudos
Message 4 of 5
(7,072 Views)
dim result : result = DirListGet("C:\tmp", "*.dat", "filename", "FullFilenamesRecursive")
dim fl : for each fl in result
  MsgBox fl
Next

Works fine for me and even recursive.

Alternatively but with mucg more effort and the same result.

Option Explicit  'Forces the explicit declaration of all the variables in a script.

dim folderPath : folderPath = "C:\tmp"
dim files : files = GetFileListRecursive(folderPath)
dim fl : for each fl in files
  MsgBox fl
Next

Function GetFileListRecursive(folderPath)

  dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
  dim results : results = Array()
  GetFiles fso, folderPath, results

  GetFileListRecursive = results

End Function

Sub GetFiles(fso, folderPath, results)

  dim folderObj : Set folderObj = fso.GetFolder(folderPath)

  dim f : for Each f In folderObj.Files
    if(0 = StrComp(fso.GetExtensionName(f), "dat", 1)) then
      dim index : index = ubound(results) + 1
      redim Preserve results(index)
      results(index) = f.Path
    End If
  next

  dim d : for Each d In folderObj.SubFolders
    GetFiles fso, d.Path, results
  next

End sub

 

 

0 Kudos
Message 5 of 5
(7,035 Views)