LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to append a sequential number to a filename

I'm looking to write a method that will append a sequential number to filename if the file already exists.

 

Currently the user will input a filename and path into a dialog box along with the .csv type attachment. And ideas on how I could implement this?

 

-- Brad

0 Kudos
Message 1 of 10
(5,610 Views)

Use the Check if File or Folder Exists function to find out if the file is already there. If so, modify the name of the file to insert your number.

 

To learn more about LabVIEW it is recommended that you go through the tutorial(s) and look over the material in the NI Developer Zone's Learning Center which provides links to other materials and other tutorials. You can also take the online courses for free.

Message Edited by smercurio_fc on 08-18-2008 01:21 PM
Message 2 of 10
(5,609 Views)

I've only been using LabVIEW for about 7 weeks now. I understand almost all of the basic concepts behind programming, however, I'm unsure how to break apart a string, detect what number is already appended (if there is one) and increase it by one, then pass it back into a filename using LabVIEW. I'm assuming its going to be a simple case statement, but I don't know how to implement the "true" case.

 

-- Brad

Message Edited by Bard on 08-18-2008 01:43 PM
0 Kudos
Message 3 of 10
(5,602 Views)

Hi Brad,

 

There may be better ways to do it, but this should work. 

 

edit, first picture was incomplete implementation. 

Message Edited by lmtis on 08-18-2008 02:29 PM
Jim

LV 2020
Message 4 of 10
(5,579 Views)

Jim,

 

I've looked at your picture and I've got two problems. One I cannot find the "List" function anywhere. I'm using LabVIEW 8.5.1 PDS, should that matter? What is it called? Two is you have the basename there as a constant. How could I dynamically get the basename of the file, because I'm not going to know what the user inputs as the base filename?

 

PS I really appreciate your help

 

Thanks in advance.

 

Brad

Message Edited by Bard on 08-18-2008 03:13 PM
0 Kudos
Message 5 of 10
(5,559 Views)

Bard wrote:

Jim,

 

I've looked at your picture and I've got two problems. One I cannot find the "List" function anywhere. I'm using LabVIEW 8.5.1 PDS, should that matter? What is it called?


"List Folder". It's in the File I/O -> Advanced. It has a different icon since the example was done in an earlier version of LabVIEW. Wire in a value to the "pattern" input to limit it to return CSV files. For example, wire in a value of *.csv.

 


Two is you have the basename there as a constant. How could I dynamically get the basename of the file, because I'm not going to know what the user inputs as the base filename?


Replace the constant with a control. 

 

Message 6 of 10
(5,536 Views)
As smercurio indicated, my basename is the filename input by the user.  If you wire this to the input of  "list folder" it will return all files named "basename*".  In the for next loop my example takes all files named "basename*", strips off the extension with the match pattern vi (assuming that they are ".csv" files), and makes an array of the sequential numbers.  It then finds the largest Sequential number, increments it by one and builds a filename for that next file, and saves it.
Jim

LV 2020
Message 7 of 10
(5,524 Views)

Jim,

 

I think I migth be missing something. I've implemented your method into my program and everything seems to be working. However, when I highlight the execution is shows that the for loop is not being executed. No data is passed in and only 0 is passed out every time, thus making the filename xxxx1.csv everytime. 

 

Any ideas?

 

PS I've haven't done alot of work with for loops, I usually use while loops, maybe I'm missing something there?

 

Thanks!

 

-Brad

0 Kudos
Message 8 of 10
(5,500 Views)

Hi Brad,

 

That sounds to me like your file search is not finding any files that match your search pattern.  Verify that the path and pattern going to the list directory VI are correct and put a probe on the output to see the array coming out of it.  Make sure that indexing is enabled on the input of your for loop.  Make sure append an asterisk after the base pattern - I just realized that this may be what I forgot to tell you.
Jim

LV 2020
0 Kudos
Message 9 of 10
(5,479 Views)

Great Jim that worked! That is what was missing, the asterik. I appreciate your help!

 

-Brad

0 Kudos
Message 10 of 10
(5,469 Views)