-3

I have a folder with lot of zip files based on semantic versions i want to get the top 5 versions and delete rest. I want to know how can i query the latest top 5 versions in a query

        MyService- 1.0.2.5.zip
        MyService- 1.0.2.6.zip
        MyService- 1.0.2.7.zip
        MyService- 2.0.0.63.zip
        MyService- 2.0.0.64.zip
        MyService- 2.0.0.65.zip
        MyService- 2.0.0.66.zip and so on
        MyService- 3.0.0.11.zip
        MyService- 3.0.0.12.zip and so on 

        I want the top 5 or top 1 version is there any utility or function which gives me that abilitya
Imran
  • 71
  • 1
  • 8
  • What do you mean by "query"? Folders don't support "queries". Do you want to write a program? In which language? – JB Nizet Dec 31 '17 at 14:44
  • I want to write a program in groovy but even c# is ok, I am more keen to know the logic to get the top 5 version? is there any logic pre defined – Imran Dec 31 '17 at 14:51
  • Parse the file name to extract the version, parse the version string into a class containing major, minor and patch version numbers, group the files by their name, and for each group, sort them by version, then only keep the last 5 ones. – JB Nizet Dec 31 '17 at 14:54
  • Pleas,provide more information. The question is impossible to answer at this moment. – Mat Dec 31 '17 at 15:38
  • MyService- 1.0.2.5.zip MyService- 1.0.2.6.zip MyService- 1.0.2.7.zip MyService- 2.0.0.63.zip MyService- 2.0.0.64.zip MyService- 2.0.0.65.zip MyService- 2.0.0.66.zip and so on MyService- 3.0.0.11.zip MyService- 3.0.0.12.zip and so on I want the top 5 or top 1 version is there any utility or function which gives me that ability – Imran Dec 31 '17 at 16:01

1 Answers1

0

Searching the Google for SemVer C#, yields a couple of .NET libraries and other related information. The Google also list some Java libraries.

As for the algorithm, sort the list using the SemVer precedence semantics, specified in SemVer Specification #11, then pick the first N items in the list.

jwdonahue
  • 6,199
  • 2
  • 21
  • 43