05-16-2012 03:33 AM
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
05-16-2012 04:36 AM
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
05-16-2012 04:45 AM
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.
05-16-2012 06:14 AM
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
05-25-2012 08:52 AM
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