Example Code

Generate Unique File Path and Create File

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 code allows the user to create a New File, if it exists the VI add a number at the end of the file name.

If you try to create MyFile.dat and it already exists this VI will open a file named MyFile1.dat and pass back a reference to this new file. If several numbered files exist it will find the next available number.

 

Description

This VI checking if the File Name is already exists (error code = 10) that determines to add a number at the end of the File Name. Using Strip Path with Search/Split String functions it gets the File Name and the Extension. With a initialized Shift Register, Increment and Number to Decimal String function it gets the number to add. Using Concatenate and Build Path, creates the New File Name.

The While Loop executes until there is no error in the Open/Create/Replace File Function.

 

Requirements

LabVIEW 2012 (or compatible)

 

Steps to Implement or Execute Code

  1. Explore and select File Path Input Value
  2. Run VI
  3. Run VI twice to create a New File adding a number at the end of the file name

Additional Information or References

11802.png

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

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