Example Code

Creating and Opening a File from a Non-existent File Path using LabVIEW

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

Code and Documents

Attachment

Overview
This example highlights how to dynamically and programmatically create a file and open a reference to it, when both the file and the directory structure need to be created.


Description
Without creating non-existent folders in the specified file path, an "Error 7" error is caused by the "Open/Create/Replace File" vi. This example shows how to prevent this error from happening. 

"Create Folder vi" is used to create the missing folders, only if they don't already exist. The "Create Folder vi" causes an error if the specified file path already exists, so if it does already exist, we don't want to call the "Create Folder vi".  To accomplish this the "Check if file or folder exists vi” is used to control the case structure with the "Create Folder vi" inside.

 
Requirements

  • LabVIEW 2012 Base Development System (or compatible)


Steps to Implement or Execute Code

  1. Download the VI “Dynamically Create Directory 2012 NIVerified.vi”
  2. Run the program

 

Additional Information or References
VI Block Diagram

block.png

 **This document has been updated to meet the current required format for the NI Code Exchange.**

Product Support Engineer
National Instruments

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.