DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

filex variables

How do I include variables with * commands in a filex command, written within a SUD?
 
I am using the filex command to search for a specific file name, and I would like to include a T2 variable with some wildcards.
The T2 variable has been defined by another SUD
What is the correct syntax?
 
  If FilEx("D:\New_PC\Testing\New Rig\data\*(T2)*.txt") Then  
 
 
 
If the outcome is true then I load the file,
Filepath.Text = FileDlgname
 
  Call AsciiLoad(filepath.text, 0)            '{Import}
If false then a say that it does not exist.
 
Thanks
0 Kudos
Message 1 of 5
(3,702 Views)

Hello!

Try this:

If FilEx("D:\New_PC\Testing\New Rig\data\" & T2 & ".txt") Then

Matthias

Matthias Alleweldt
Project Engineer / Projektingenieur
Twigeater?  
0 Kudos
Message 2 of 5
(3,695 Views)

Thanks vey much.

I still would like to return the name of the file and load it into the data portal.

Does Fileex return a variable other than TRUE or FALSE?

Is there a better way to search for a file with that variable in its title and load it.

The variable only contains the middle part of the file name.

 

ie file name = mydata220207.txt

I would like to search for all files with 220207 and then load it.

0 Kudos
Message 3 of 5
(3,678 Views)

Hello Stagsden!

As far as I know is there no pure DIAdem solution. My aproach is to get all files of a folder with the file system object and make the wildcard compare with the regular expression object.

The example code:

Option Explicit

Dim oFSO
Dim oFolder
Dim oFile
Dim oRegExp
Dim sgPath
Dim sgMask

' Input parameter
sgPath = "D:\Programme\National Instruments\DIAdem 10.1\Libr\Dat\"
sgMask = "E*.tdm"

' Get the folder via the file system object
Set oFSO    = CreateObject("Scripting.FileSystemObject")
Set oFolder = oFSO.GetFolder(sgPath)

' Get the regular expression object and convert wildcard string to regular expression
Set oRegExp = CreateObject("VBScript.RegExp")

oRegExp.IgnoreCase = True
oRegExp.Pattern    = "^" & replace(replace(replace(sgMask,".","\."),"*",".*"),"?", ".") & "$"

' Loop through all files and show a message box for every match
For Each oFile In oFolder.Files
  If oRegExp.Test( oFile.Name) Then
     MsgBox oFile.Name
  End If
Next

Matthias

Matthias Alleweldt
Project Engineer / Projektingenieur
Twigeater?  
0 Kudos
Message 4 of 5
(3,670 Views)
Hello Stagsden!
 
It is always a good idea to put useful code in a function. Here is the optimized version.
 
Function (result with full path in a string array):
' VBS Dir, Result as string array
Function Dir(ByRef sgPath, ByRef sgMask )
  Dim oFSO
  Dim oFolder
  Dim oFile
  Dim oRegExp
  Dim asgFiles

  ' Prepare result array
  asgFiles = Array()

  ' Get the folder via the file system object
  Set oFSO    = CreateObject("Scripting.FileSystemObject")
  Set oFolder = oFSO.GetFolder(sgPath)

  ' Get the regular expression object and convert wildcard string to regular expression
  Set oRegExp = CreateObject("VBScript.RegExp")

  oRegExp.IgnoreCase = True
  oRegExp.Pattern    = "^" & replace(replace(replace(sgMask,".","\."),"*",".*"),"?", ".") & "$"

  ' Loop through all files and add it to the result array
  For Each oFile In oFolder.Files
    If oRegExp.Test( oFile.Name) Then
        ReDim Preserve asgFiles(UBound(asgFiles)+1)
        asgFiles(UBound(asgFiles)) = oFile.Path
    End If
  Next

  ' Result
  Dir = asgFiles
End Function

Test script:
Option Explicit

Dim sgFile
Dim asgFiles

asgFiles = Dir("D:\Programme\National Instruments\DIAdem 10.1\Libr\Dat\", "E*.tdm")

For Each sgFile in asgFiles
  MsgBox sgFile
Next
Matthias

Message Edited by Twigeater on 02-28-2007 08:16 AM

Message Edited by Twigeater on 02-28-2007 08:16 AM

Matthias Alleweldt
Project Engineer / Projektingenieur
Twigeater?  
0 Kudos
Message 5 of 5
(3,666 Views)