LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Read all the files in a folder over and over again

Solved!
Go to solution

I want to develop an application that reads all the files in a folder, and once its done reading those files it reads all the files again.

The purpose for this application is to read all the files in a folder that are continuously being stored in that folder, so that when a new file is created, that file is also read by the application. I then need to compare the date and time in which the file was created to the actual date and time of the system, so that way I can get the most recent file, and then  I will do other operations with this file.

The thing is that I know how to read all the files in a directory, but I don't know how to cycle through those files again, in order to look for the most recent one, and I don't know how to make the comparison of the time stamps, because I need a precision of one second in the system time and the time the file was created.

Can someone please help me?

Thanks in advance!

0 Kudos
Message 1 of 16
(2,932 Views)

Moving past the double post here, this doesn't seem like it should be that difficult.

 

Simply use the "List Folder" to generate a list of the items included in the folder that you want to examine. This returns an array of filenames, you can then use this array in for loop with the "File/Directory Info" vi to find the information about the files. This information includes the last modified file information as well as a range of other information. Simply comparing these timestamps will tell you which is the newest file. Seems pretty straight forward to me, but 'll see about knocking up a quick VI soon if you can't figure it out for yourself.

0 Kudos
Message 2 of 16
(2,918 Views)

I think that I just went the wrong direction.

What I wanted to do in the first place, was to rename and overwrite every new file in a directory with the same name and file extension, so that every new file overwrites the old file. The thing is that the list folder only lists the files the first time and then keeps on telling me there are no files to be read even though there are new files.

What I need now is a way to overwrite the old files with the same name, and keep searching for every new file that is going to be stored in the directory.

I will leave the code that I have right now, so that you can tell me what do I need to modify in order to read every new file that's going to be created in that directory.

Thanks in advance for your help!

0 Kudos
Message 3 of 16
(2,905 Views)

You are still struggling with dataflow and some very basic programming concepts. you should really start with sime simple tutorials fist.

 

Your "list folder" operation executes exactly once at the start of the program and never again (because it is not inside the loop!). As soon as the number of iteratios exceeds the number of files, you are only looking at nonexistent files, forever!

 

You are copying each file to "a.txt", ovewriting what you did a nanosecond ago. Seems absolutely pointless.

 

Your loop still spins at nearly infinite rate, doing nothing useful once you run out of files.

 

Think!!!!!

0 Kudos
Message 4 of 16
(2,897 Views)

I'm not entirely sure why you would want to do what you are doing when it seems overly complicated. Could you not simply use the Replace option for open/replace file so that every time you access the file it is simply overwritten?

Image.JPG

0 Kudos
Message 5 of 16
(2,890 Views)

The problem I'm having is that I can't connect the filename of the list folder to the name in the build path if I place the list folder inside the while loop, and if I create a while loop to enclose everything except the path, it still looks for a non existent file forever after having searched all the files the first time.

How can I fix this?

Thanks in advance!

0 Kudos
Message 6 of 16
(2,886 Views)

We told you in your other thread to use an autoindexing FOR loop on the file names as an inner loop. Place a while loop with a small wait around everything. You still wire a folder path to the list folder as before. Whenever all files have been processed, the list is redone and processed again.

 

You have significantly more problems, as outlined earlier. This entire execrise seems rather mindless.

0 Kudos
Message 7 of 16
(2,880 Views)

The thing is that I will end up having multiple files with different names, and I want each of these files to have only one name and for each one of them to overwrite each other. I already have an application that updates the file automatically even if its being overwritten, but in order for my project to work, I need to have only one file and this file should be updated with the new ones that are going to be created.

0 Kudos
Message 8 of 16
(2,879 Views)

I still think that having a simple replace file rather than generating a new one seems to be the solution to all of your problems here. This way there will be only a single file that will be constantly changing and updating. If you simply ensure that 'all' of your access methods to the files use the same name and replace the file then it should do exactly what you are looking for. I don't even want to know how many things you have writing to files that you are just discarding or overwriting, when you should only have one place or maybe one FGV that is handling the writing to this one file.

0 Kudos
Message 9 of 16
(2,873 Views)

Please explain in detail how the project works. All this seems very pointless. I am sure there is a much more sane solution.

0 Kudos
Message 10 of 16
(2,870 Views)