LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Automatically read next file in folder

Solved!
Go to solution

HI I am trying to read in files and use the attached vi to calculate the area under the curve.  everything works, except that I would like the functionality of being able to automatically select the "next file" or the "previous file" with out having to reopen user dialogue.  Any help would greatly be appreciated. 

0 Kudos
Message 1 of 5
(3,025 Views)
Solution
Accepted by topic author MLH Group TECH

I haven't look at your vi but attached is a way to navigate to previous and next file.  You will need to add some range check (if file is first or last in its directory).

Ben64

 

 

Message 2 of 5
(3,020 Views)

I don't see where you determine what the first file is to be processed.

 

You have various indicators called name, appended path, and stripped path.  You seem to be jumping back and forth on creating paths, but I don't see where you initially determine what is the file.  I think you have problems with misuse of local variables that lead to race conditions where you don't know what is the value in the local variable because it is and when a data value was last written to the indicator.  This really manifests itself in the file name scheme.  You have a local variable of appended path that determines the stripped path and name and puts them into the indicator terminals.  But simulataneously, you are using local variables of stripped path and name to determine the value to put in the appended path indicator terminal.

 

I think you have a lot of the correct elements in there.  List Folder is going to give you the list of files in the folder.  I don't know how you determine what Next file is vs. Previous file.  Do you want it to be alphabetical, by file date, or just whatever order that the operating system returns the files?

 

Once you have an array of files (from list folder) then using the integer wire to determine which of the elements you want to use is correct.  But you aren't quite doing that.  You are taking the Name local variable, turning that string into an array (which will have exactly one element) and using the index of element (again a local variable) to either return that name back again, or an empty string in the event that the index element is greater than zero.

 

Overall, you have a lot of things happening in parallel when they are really sequential processes.  As a result, you are using local variables to pass data back and forth between your two case structures, but there is no control over whether the data is fresh from that loop iteration, or stale from the previous loop iteration.

 

Set up a flowchart as to what the sequence of steps would be and program to that.  You may want to look into event structures to handle button presses for next file, previous file, and read data, so that it executes the reading and analyzing of the files, and also updates the file index either 1 higher or lower when those buttons are pressed.

0 Kudos
Message 3 of 5
(3,015 Views)

I agree with Ravens Fan. You have a lot of work to do on your program before you worry about opening files. You should look into a state machine system for what you are doing. If you ge tyour code more orginaized then I think you will find that it is easier to accomplish things as you move forward.

 

Here is how I would do just the file index stuff.

Tim
GHSP
0 Kudos
Message 4 of 5
(3,008 Views)

I am just trying to modify an existing code, and I agree that it is really messy, inefficient and unorganized, I will rework the code. Thank you for all your input Using the event structure is exactly what I was looking for.  Thanks

0 Kudos
Message 5 of 5
(2,999 Views)