02-26-2007 11:10 AM
02-26-2007 04:19 PM
Hello!
Try this:
If FilEx("D:\New_PC\Testing\New Rig\data\" & T2 & ".txt") Then
Matthias
Matthias Alleweldt Project Engineer / Projektingenieur | Twigeater? |
02-27-2007 01:05 PM
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.
02-27-2007 04:37 PM
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? |
02-28-2007 01:15 AM - edited 02-28-2007 01:15 AM
' 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
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
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? |