08-18-2008 01:15 PM
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
08-18-2008 01:21 PM - edited 08-18-2008 01:21 PM
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.
08-18-2008 01:42 PM - edited 08-18-2008 01:43 PM
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
08-18-2008 02:26 PM - edited 08-18-2008 02:29 PM
Hi Brad,
There may be better ways to do it, but this should work.
edit, first picture was incomplete implementation.
08-18-2008 03:12 PM - edited 08-18-2008 03:13 PM
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
08-18-2008 04:57 PM
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.
08-18-2008 07:33 PM
08-19-2008 07:59 AM
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
08-19-2008 08:32 AM
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.
08-19-2008 08:43 AM
Great Jim that worked! That is what was missing, the asterik. I appreciate your help!
-Brad