LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Create unique filename by auto-increment path

I needed a program that would take in a pathname, see if the file name already existed at that location, and if so it needed to auto-increment the file name. I wanted it to work the way windows inherently does when you copy a file of the same name into a location because that seems the most natural to me. I was running into problems with the ftp functions in the internet toolkit becaues if the local file already exists at the path you input, it just doesn't perform the get files function.

 

I discovered after searching the forums that a lot of people run into this all the time and usually the way they get a unique file name is by adding the date and time to the end of the file. This is both effective and informative, but results in unnecessarily long and ugly file names. 

 

So I made a subVI and I wanted to share it with you guys. Hope someone finds it useful. Let me know what you think.

 

 

uniquefilename help.PNG

---------------------------------
[will work for kudos]
Message 1 of 11
(13,682 Views)

Thank you for sharing this VI. You should consider upload previous versions of the VI so that users who don't have LV 2009 can look at the code as well.

 

0 Kudos
Message 2 of 11
(13,665 Views)

Nice VI (good icon!).

 

Two minor points:

  1. I would try to have the boolean option default to F with the same functionality (or append a (T) to the caption).
    Perhpas is Always a good name
  2. Give an output boolean that is true when a new file name is generated.
Ton
Free Code Capture Tool! Version 2.1.3 with comments, web-upload, back-save and snippets!
Nederlandse LabVIEW user groep www.lvug.nl
My LabVIEW Ideas

LabVIEW, programming like it should be!
0 Kudos
Message 3 of 11
(13,661 Views)

I took your suggestions

 

- appended (T) to the check existence input description to indicate its default position

- Created a "New Path?" output that idicates whether a new path was created (T) or if the inputted path was simply passed through (F)

 

And for all the users who dont have 2009... Here are some older versions for you 🙂

 

enjoy

 

---------------------------------
[will work for kudos]
Message 4 of 11
(13,652 Views)

I'll add a related example to this thread.  This old-dog has been around for a while, I spent a few minutes cleaning it up, but it by no means is as ready for prime time as yours.  (I'll probably pilfer that icon).  I use this one a lot, it lets me enter a base filename and a path and it returns the list of files with the matching pattern, pulls the number from the last one and increments.  If the path is empty you get a dialog so I usually put the path out into a shift register.  First time I run I am asked where to put the files and then I can collect data one file at a time.  Hard-wired for 4 digits, zero-padding is very important for keeping the files in alphabetical as well as chronological order.

 

 

0 Kudos
Message 5 of 11
(13,640 Views)

Your example definately pointed out a case where previous versions of my VI could output a non-unique filename.

 

If there were two files, file.txt and file(1).txt in a directory and you inputted "file.txt" into my VI it would output "file(1).txt" which would be a non-unique filename.

 

Fixed version coming shortly.

 

I am still deciding whether or not to add functionality that will allow me to input the number of digits of the number to use for increment (zero padding).

---------------------------------
[will work for kudos]
0 Kudos
Message 6 of 11
(13,628 Views)

Well it was an easy fix so here it is (without zero padding)

 

Version 1.3 🙂

---------------------------------
[will work for kudos]
0 Kudos
Message 7 of 11
(13,624 Views)

Hi all,

 

Don't forget that when you create awesome VIs that you want to share with the community, you should upload them on the NI Community.  If you've got 2009, don't forget to use the new VI Snippet feature to post pictures of your code!  Thanks for your great work!

Stephen Meserve
National Instruments
0 Kudos
Message 8 of 11
(13,599 Views)
You think this VI is awesome? Well then maybe I will post it on the NI Community. Any suggestions of which NI Community "location" to post it?
---------------------------------
[will work for kudos]
0 Kudos
Message 9 of 11
(13,587 Views)

Hi Rex,

 

You can just create it under Documents.

Stephen Meserve
National Instruments
0 Kudos
Message 10 of 11
(13,583 Views)