Reputation: 13
I work for the computer repair branch of my University's I.T. department, and our major function is to remove viruses from student's personal computers. To do this, we need the most up-to-date versions of various virus removal tools (such as Kaspersky Virus Removal Tool, and Malwarebytes Antimalware). So I wrote a C# program to download these files for us. I'm not overly concerned with the actual act of downloading the files; that much is already working (I'm simply using the DownloadFile method of the WebClient class). The problem I've run into is the fact that some of the filenames change over time, due to including the date they were last updated and/or the version number of the program. For example, the current download link for the Kaspersky Virus Removal Tool is "http://devbuilds.kaspersky-labs.com/devbuilds/AVPTool/avptool11/setup_11.0.0.1245.x01_2013_01_29_22_08.exe", but tomorrow it could potentially be "http://devbuilds.kaspersky-labs.com/devbuilds/AVPTool/avptool11/setup_11.0.0.1368.x01_2013_02_05_22_08.exe". The first solution that came to my mind was to use Regular Expressions... The problem with that is that I've never really used RegEx before, so I'm not entirely certain how to implement them into this particular situation, and I haven't found any references to similar problems.
With the current setup of the program, I have to go and change the download url's of any files that have been updated. Ideally, I'd like my program to be able to get the most recent version of these virus removal tools automatically, so that we can just set up a scheduled task to run every night.
Any help in resolving this problem of mine would be greatly appreciated... I've been pondering this particular problem for a couple of months now.
Upvotes: 1
Views: 192
Reputation: 44288
its even easier than that, the way they are naming the files means if you do a string comparison, the name that is greater will be the latest.
Just for your reference, to get the latest filename...
var client = new WebClient();
var r = new Regex("setup(.*?)exe");
var matches =
r.Matches(client.DownloadString(@"http://devbuilds.kaspersky-labs.com/devbuilds/AVPTool/avptool11/"));
var latest = matches.Cast<object>().ToList()
.Select(o => o.ToString())
.OrderByDescending(s => s)
.FirstOrDefault();
Upvotes: 2