DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Retrieving TDMS files in Directory

In the script below, I have 2 issues with the usage of DataFileLstGet :
1. The wildcard specified is (*.tdms) which I think should only look for (.tdms) files, but it is also picking up (.tmds_index) files,
     I am temporarily filtering this out by checking for the file extension length as four.
 
2. The function only returns that there are 2 tdms files in the directory pointed to, while in reality I have more than 2 files in this directory.
 
Can anyone give me an idea of what the issue could be ?  I am using Diadem version 10.2 Base Edition, VB script engine is 5,5,0,5207.
 
Thanks.
 
Option Explicit
Dim intCount
Dim ExcelFilename
Dim TDMSFilename
Dim Ret
Dim FileExt
Dim FileExt1
Dim NumFiles
FileExt1 = "TDMS"
Ret = PathNameGet("TDMSFiles Location", "D:\MFT\datamine\pmm\testresults\")
Call DataDelAll(1)
If FilEx(OutPutPath & "*.TDMS") Then
Call DataFileLstGet(OutPutPath & "*.TDMS")
'  Call MsgBoxDisp (DataFileLstLen)
  For intCount = 1 to DataFileLstLen
'  Call MsgBoxDisp (DataFileLst(intCount))
    FileExt = NameSplit(DataFileLst(intCount), "E")
'  Call MsgBoxDisp (FileExt)
'  Call MsgBoxDisp (Len(FileExt))
    FileName = NameSplit(DataFileLst(intCount), "N")
    If  Len(FileExt) = 4 Then   
        TDMSFilename = OutPutPath & DataFileLst(intCount)
        Call DataFileLoadSel(TDMSFilename,"TDMS","*/*","Load")
        ExcelFilename = OutPutPath & FileName & ".xls"
        Call ExcelExport(ExcelFilename,"", 0, OutPutPath & "EXCEL.STP")
        Call DataDelAll(1)
    End If
  Next
Else
  MsgBoxDisp("No TDMS files found")
End If
0 Kudos
Message 1 of 9
(5,514 Views)

Hello kade!

 

Have a look in help for the 'DataFileLstGet' command. The command will find all 'sub' (binary) files to ONE 'master' file (TDM/TDMS) and doesn't work like a DOS 'dir'!!!

 

Matthias

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

try this Code instead:

 

Option Explicit

Dim s
Dim oFSO
Dim oFolder
Dim oFiles
Dim oFile

Dim Ret
Dim ExcelFilename
Dim TDMSFilename


Ret = PathNameGet("TDMSFiles Location", "D:\MFT\datamine\pmm\testresults\")

Call DataDelAll(1)

Set oFSO = CreateObject("Scripting.FileSystemObject")

Set oFolder = oFSO.GetFolder(OutPutPath)
   
For Each oFile in oFolder.Files
  ' Do-It-Yourself Extension Filter
  If UCase(NameSplit(oFile.name, "E")) = "TDMS" Then
    TDMSFilename = OutPutPath & oFile.name 
    Call DataFileLoadSel(TDMSFilename,"TDMS","*/*","Load")
    ExcelFilename = OutPutPath & FileName & ".xls"
    Call ExcelExport(ExcelFilename,"", 0, OutPutPath & "EXCEL.STP")
    Call DataDelAll(1)
  End If
Next
Matthias Alleweldt
Project Engineer / Projektingenieur
Twigeater?  
0 Kudos
Message 3 of 9
(5,510 Views)

Thanks Matthias.

 

Still got a few issues:

1. It still only finds one TDMS file, eventhough I have 2 in my testresults directory.

2. The excel file is not being created correctly, it tells me the file is corrupt, this seems to also happen with my version of the script which leads me to beleive my excel maybe acting funny.

 

0 Kudos
Message 4 of 9
(5,507 Views)

Hello kade!

 

I tried with a directory with 4 files. All were found! You can add a MsgBox before the extension filter to see a complete file list.

 

Matthias

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

Ok looks like the export is working now, but the file being created is not a good excel file. I get the error "file format is not valid"

any ideas ?

 

Kunle.

0 Kudos
Message 6 of 9
(5,489 Views)

Hello Kunle!

 

I wrote my own DIAdem Excel export functions years ago so I'm not familiar with the funny build in functions. I recommend to start a new thread with this issue.

 

Matthias

Matthias Alleweldt
Project Engineer / Projektingenieur
Twigeater?  
0 Kudos
Message 7 of 9
(5,469 Views)

i narrowed it down to a diadem general error, which is not obvious what the problem is. EXCELStat retruns "100". any ideas ?

0 Kudos
Message 8 of 9
(5,461 Views)

Hello Kunle!

 

Error 100 is always beloved in DIAdem and absolut expressionless Smiley Wink! Or do you expect errors? 

 

One possible reason for you problem could be that you already have opened the output file in Excel. Excel always opens files in exclusive mode.

 

Matthias

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