LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to open all the text files within a folder at once so that they run through my VI in the correct order and the VI only needs to be ran once per folder?

Solved!
Go to solution

Hello,

 

I am currently attempting to run hundreds of text files through my VI by only having to run the VI once and having labview open each text file in numberical order that are contained in a single folder.

 

Typically, I run each file one at a time through the VI, taking hours to run all the text files through. I was wondering if there is a way that I can specify a target folder and then each text file from the target folder will be opened and ran through my VI  in numberical order (each file is in order i.e. MM_01, MM_02, MM_03...). Currently I open one file at a time, run it through "read from spreadsheet", then index the array, and run it through filters etc. to obtain the data I require. I am hoping there is a way to do this, as it will save days worth of work.

 

Thank you in advance for your help.

0 Kudos
Message 1 of 18
(6,771 Views)
Solution
Accepted by topic author CSmith8

Capture.PNG


"Should be" isn't "Is" -Jay
Message 2 of 18
(6,761 Views)

Are you just wanting to read all of the files within a folder then close them again after getting the data?

 

Just use the List Folder VI from the File IO pallette. You can input a pattern like "*.txt" to get all files of a certain type within that folder. Then fun that array of filenames into a For loop, Build Path with the original folder path, and Read from Spreadsheet.

 

Edit: Do what JeffP gave you. If you don't want the files within subfolders, do this:

Open Files In Folder.png

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


Message 3 of 18
(6,758 Views)

Thank you for a quick response.

 

How do you suggest i resolve the issue of different data types in order to use this function? I have tried a few different ways and have whenever I adjust, it wont run through my sub VI's correctly due to being different data types.

0 Kudos
Message 4 of 18
(6,703 Views)

What different data types? The For loop is indexing through the array one by one, so you don't need to do an Array Index operation.

 

The snippet I included above should make it clear what to do once inside the For loop.

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


0 Kudos
Message 5 of 18
(6,695 Views)

@CSmith8 wrote:

Thank you for a quick response.

 

How do you suggest i resolve the issue of different data types in order to use this function? I have tried a few different ways and have whenever I adjust, it wont run through my sub VI's correctly due to being different data types.


You have to READ THE FILES.  Jeff just showed you how to use a FOR loop to go through the files.  You still need to open the files, read them and then process the data.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 6 of 18
(6,692 Views)

Thank you, I missed though and thought that opening the files did that for me. I now have it working and running my files through while they are matching the ones I ran individually.

 

Thank you all for your help!

0 Kudos
Message 7 of 18
(6,657 Views)

@crossrulz wrote:

@CSmith8 wrote:

Thank you for a quick response.

 

How do you suggest i resolve the issue of different data types in order to use this function? I have tried a few different ways and have whenever I adjust, it wont run through my sub VI's correctly due to being different data types.


You have to READ THE FILES.  Jeff just showed you how to use a FOR loop to go through the files.  You still need to open the files, read them and then process the data.


I had assumed from CSmith8's original post that the text file processing vi worked.  just drop that vi into the for loop and wire the file name in!

 

Alternately, attach the code that processes the file and a sample file.  I bet we can show you a thing or two about how to do it cleaner and faster Smiley Wink then point you to the right learning resources so one day you can show us some new tricks.

 

-Old Dog Jeff·Þ·B

(Why does everyone forget the commas?  alt+0183 alt+0222 alt+0183) 


"Should be" isn't "Is" -Jay
0 Kudos
Message 8 of 18
(6,655 Views)

hi i tried to run the vi but i keep getting an error which says "file is not a resource file". the error is highlighting the list folder vi. can you help me fix this?

0 Kudos
Message 9 of 18
(6,588 Views)

Hi ceciliap004,

 

Could you post a screenshot of the code you are trying to run. What kind of file are you trying to open? 

Please provide more information about the issue you are having.

 

Regards,

Carolina 

 

0 Kudos
Message 10 of 18
(6,544 Views)