LabVIEW Idea Exchange

cancel
Showing results for 
Search instead for 
Did you mean: 
smmarlow

Add "Created New?" output to Open/Create/Replace file I/O Primitive

Status: New

The Open/Create/Replace file I/O primitive is pretty powerful.  It will check to see if the file is there for you, and, if not, create a new one.  I use the "Open or Create" option often when generating multiple delimited text files in long term tests.  When a new file is created, I need know so I can add a header, and I need to skip the header operation if the file is being appended.  Sure, I could check to see if the file exists before trying to open it, but then wouldn't that just make the power of the Open/Replace/Create function redundant?  Some operation took place based on my input to the "operation" terminal, and whether or not the file exists.  Unfortunately, I have no idea what that operation was, because the function doesn't tell me. Let me know if the Open/Create/Replace function created a new file so I can add my header.  

 

New File Feature.png

 

This is not without precedent.  For example, the "Obtain Queue" primitive has an option to create a new queue if a queue of the given name is not found.  It let's you know if the new queue was created:

 

created new.png

5 Comments
crossrulz
Knight of NI

You also need to move the file pointer to the end if Opened.  That is not needed if the file was created.

 

I normally use Create Or Replace.  But I do know the situations where this could be useful.  Not sure if they are often enough to ask NI to work on this or something else that I definately could use.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Yamaeda
Proven Zealot

You can ofcourse use a Check if file exists before, but i agree this should be an output as it's a fairly integral part of said function.

Kudoed

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
kittentronic
Member

Any time you call separate functions to check a file and then to do something with the file, you have a potential race condition. It might exist when you check it but have been deleted by another process by the time you do the Open/Check/Replace. 

AristosQueue (NI)
NI Employee (retired)

> Any time you call separate functions to check a file and then to do something with the

> file, you have a potential race condition. It might exist when you check it but have been

> deleted by another process by the time you do the Open/Check/Replace

 

LabVIEW faces the same problem when it overwrites the file inside the primitive -- check exists, then overwrite.

I would still do this feature despite that race condition.

kittentronic
Member

At an OS level though, can't you first attempt to open the file, trap the error if it didn't exist, then create it if necessary? I guess there's always scope for a race condition on a multithreaded OS (what if someone else creates the file in between you attempting to open it and attempting to create it?) but I assume that within the primitive you can (a) do more to make these operations atomic, and (b) do error trapping and recovery that would be cumbersome for the LabVIEW programmer to write every time.

 

I'm fully in agreement that this feature should be added, anyway!