LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Add multiple files one by one in an array

Hi folks,

 

I want to add multiple files from a folder in an array but I want to add them one by one. After adding the desired number of files, I want the code to be stopped and use the array for other purposes. It's easy to give a path to folder and build array but the selection of the files. I want the code to prompt for which file I want to add and keep doing it until I added the desired number of files and then cancel the prompt to stop the code. 

Seeking ideas. 

0 Kudos
Message 1 of 10
(3,303 Views)

Seems trivial. What have you tried?

 

In a proper state machine, the code will not "stop", just proceed to another state, e.g. for the "other purpose", or to an idle state waiting for the next command. So you want an automatic prompt for each file? When should the adding of file stop? (E.g. if the file dialog is canceled?)

0 Kudos
Message 2 of 10
(3,295 Views)

Hi altenbach, 

 

At the moment I am at the point of thinking how this can be done. Once I ll have an idea, doing it won't be an issue. 

 

This is exactly I want "So you want an automatic prompt for each file? When should the adding of file stop? (E.g. if the file dialog is canceled?)"

0 Kudos
Message 3 of 10
(3,272 Views)

I'd pop up a dialog VI that has a cluster array of a Boolean and a FileName. Tick the ones you want, press OK and it filters those out and continue.

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
Message 4 of 10
(3,244 Views)

A few more ideas:

 

  • The file dialog has an option to select multiple items (uncheck "limit selection to single item"). Once the dialog pops up, you can ctrl-click as many files as you want and you'll get an array of paths out. No need for looping.

altenbach_0-1636473414310.png

 

 

  • Have a control for a folder and pattern and populate a listbox with all matching file names. Now you can select multiple items or e.g. toggle a checkmark symbol by double-clicking. (e.g. similar to what I use here)

 

I would stay away from repetitive file dialogs, because they make it difficult to see what has already been picked, for example.

Message 5 of 10
(3,220 Views)

Thank you guys for the ideas. 

 

Just last thing, the chosen files are going into array in alphabetic order rather than in the order I am clicking them. I want the file to go at the top of the array which is clicked first in the folder and vice versa. 

0 Kudos
Message 6 of 10
(3,201 Views)

Try Sort 1D Array.vim (assuming you have LV 2021).

 

Eric1977_0-1636563288266.png

 

0 Kudos
Message 7 of 10
(3,164 Views)

@HassanIqbal wrote:

Just last thing, the chosen files are going into array in alphabetic order rather than in the order I am clicking them. I want the file to go at the top of the array which is clicked first in the folder and vice versa. 


You can use a multicolumn listbox (similar to already suggested) and display a sequence number with every click in the second column, then sort entries by that value at the end. (Of course you need mechanisms to undo and edit later, e.g. if you accidentally clicked in the wrong order. You should also add some sanity checks to prevent entering the same path twice. 

0 Kudos
Message 8 of 10
(3,160 Views)

@Eric1977 wrote:

Try Sort 1D Array.vim (assuming you have LV 2021).


That's the opposite. The OP does NOT want them sorted, but in the order they have been clicked.

0 Kudos
Message 9 of 10
(3,159 Views)

Ah. Read that post too fast.

 

With that said, it looks like the the native Windows dialog wants to reorder the files as they are selected. This Stack Overflow post reads like it is doing just that and developers should "roll their own" mechanism. 

0 Kudos
Message 10 of 10
(3,143 Views)