DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

check whether a file is fully saved or not

Hello,

 

I need to check, whether a bigger file is already fully saved or not. My idea is to create a loop with two times asking the current file size and a pause between this two commands. If booth file sizes are not idenical, then i know, saving is still in progress. Is there another possibility to realise that issue more professional?

 

Regards

 

Sven

 

0 Kudos
Message 1 of 4
(4,109 Views)

Hi Sven,

 

What type of file is being written here-- ASCII, TDM, TDMS, etc.?  What program is writing the file?  It may be possible for the writing program to leave a more elegant clue for DIAdem to notice.  Perhaps the header file is only written at the end, or perhaps the data file is blocked as read-only for all other applications (including DIAdem).

 

This would be a good question for Twigeater, I haven't actually struggled with this particular problem myself.

 

Brad Turpin

DIAdem Product Support Engineer
National Instruments

0 Kudos
Message 2 of 4
(4,103 Views)

Hello Brad,

 

this is an general problem, cause I want to handle different file types in a user interface for control a test rig, which stores data in project folders and modifies this data in different ways. All this I try to realise with DIAdem script (V.11).

In this specific case there is the testrig, which is running the old unix operating system Solaris. I've built a network with a central NAS - system to handle the data. At first I run my script on a WINXP Pro pc. While the script is running and stoped for measurement, the test ill be performed and the unix pc of the test rig stores the data into a NFS - folder on the NAS - system. This specific folder is just a temporary one, when (the slow!) storage process is finished (this is the moment I'm looking for!), I continue my script and copy the data files in a project folder structure for save wnd work with them.

The measured data files are kind of ASCII-files (you can open them in Excel or any editor software), but they have different extensions. The most important one is an *.TAB, otherones have extension *.BCE, *.DCS, *.DCR, *.PAR or some even have no extension. In another step I want to move EXCEL-files too.

The core problem is to be shure, that a file is fully transfered/stored to prevent access to it, while file is handled by another process. I want to be sure, that I dont run in trouble by access a file which is not fully stored, cause this can corrupt it and it is impossible to open the file after.

 

Regards

 

Sven

0 Kudos
Message 3 of 4
(4,077 Views)

Hello Sven!

 

In the past I had build a service function in GPI DLL for a similar task but I think it could be possible to implment something similar with VBS.

My aproach would be to test if the file exists first and then try to open it for append writing. If this fails you can assume that the writing process is still in progress. This aproach will only work if the writing process keeps the file open until it is completly written.

You can try it with this code:

Option Explicit Dim fso Dim file Dim filename

 

Const ForAppending = 8 Set fso = CreateObject("Scripting.FileSystemObject") filename = "C:\test.xls" If fso.FileExists(filename) Then On Error Resume Next Set file = fso.OpenTextFile(filename, ForAppending) On Error Goto 0 If IsObject(file) then MsgBox "ready" Set file = Nothing Else MsgBox "write in progress" End If End If

If this works in your environment you can build a loop with this query including a sleep command. A timeout for this loop might be reasonable as well.

 

Matthias

Matthias Alleweldt
Project Engineer / Projektingenieur
Twigeater?  
0 Kudos
Message 4 of 4
(4,069 Views)