I have been unable to find a solution to my problem with Google, I was wondering if anyone can give any advice.
I have a folder full of files looking like this:
device1_ip_1234asdf.txt
device1_stats_1234asdf.txt
device1_ip_1234asdf2.txt
device1_stats_1234asdf2.txt
device2_ip_1234asdf.txt
device2_stats_1234asdf.txt
device2_ip_1234asdf2.txt
device2_stats_1234asdf2.txt
...etc
where there are multiple log files downloaded of different types for different devices.
I only need the latest log files for each device, so after processing the folder should look like this:
device1_ip_1234asdf.txt
device1_stats_1234asdf.txt
device2_ip_1234asdf.txt
device2_stats_1234asdf.txt
There is no way to tell the latest files from the file name, it has to be determined from the date modified tag.
I need to write a script that basically goes:
get list of files for device1, log type ip
del device1_ip* where file is not latest
get list of files for device1, log type stats
del device1_stats* where file is not latest
repeat for device2, device3, etc
Can anyone point me in the right direction? I'm sure I could do this easily with bash, but windows batch files have me stumped.
I have struggled to find a way to just populate an array of file names.