09-05-2013 04:51 AM
Hello to all,
I need to know if, given a folder, it is possible to read only the last file of this.
In particular, I have to make a program that opens a folder and read only the last file of all the subfolders contained in it cyclically.
Someone can help me?
09-05-2013 05:39 AM
I am attaching pictures of the front panel and block diagram.
I wish the program opened cyclically 3 folders in "folder name" and put the last file of each in "selected file path" (in order to create a sort of array of paths).
I make myself clear?
09-05-2013 05:45 AM - edited 09-05-2013 05:47 AM
You can get all the files and their information (last mod) from the Advanced File Functions Palette.
<mta> Modify this example to use the Recursive File List VI to operate on all of the subfolders.
09-05-2013 06:07 AM
Hi Jim.
Maybe I have not explained well but I just need a loop that will open the folders one at a time and take the last file of each of them. So that later can read all the latest files.
09-05-2013 06:44 AM
Give this guy a try. I used recursion (and therefore reentrancy) to go through each folder and adding on the latest file for each folder.
09-05-2013 07:06 AM
thanks to both of you but I have to find a solution to my scheme ... could you tell me how to do?
09-05-2013 07:28 AM
Please clearify. How was my code not meeting your needs?
09-05-2013 07:32 AM
I've shown you how to get the last file of a folder (assuming that by "last" you mean the latest modification date). I've further suggested that you can extend my snippet to get what you've described. crossrulz has shown you recursion in his solution. What more do you need? What have you done?
Show me your code, Wireworker, and I'll show you mine!
09-05-2013 07:37 AM
I'm sorry, I think I don't understand how your code work...
Can you explain?
09-05-2013 08:12 AM
Jim's code is getting the list of files in a folder using List Folder Contents. Using a FOR loop, he is using Build Path to create the file path and then using File/Directory Info to look at the last modified time. The FOR loop outputs an array of these modifcation times. He then used Array Max and Min to find the newest time and what index that time was in the array. Using that index, use Index Array on the file list to get the name of the last modified file.
In my code, I used this same concept, except I added a FOR loop to go through the folders in the folder. I had the VI call itself (well, a clone of itself) to handle the recursiveness. My VI results in the latest file from each directory inside of the given folder.