I have a folder ~/ConfigurationDirectory. The sub-folders within this folder are named as follows
5.0.0.1
5.0.0.2
5.0.0.3
…
Now, the requirement is that – Identify the folder which has the “largest” name numerically and create a copy of the folder. Rename the new folder as 5.0.0.n+1 (assuming that the largest numerically available folder is 5.0.0.n)
I have written code which will identify the largest named folder. Also, I have written the code which will do the copy of folder and sub-folders. What I am not able to get is, how do I get the name of the new folder, i.e., 5.0.0.n+1
How do I do this in C#? Any pointers would suffice rather than complete coding.
Thanks!
Assuming the numbers you’re working with are not simple four-part version numbers, you’re going to want to use the string.Split() to break up the folder name, and then Convert.ToInt32() or int.Parse() to turn the last chunk into a number. From there, you increment it, and then use something like string.Format() to turn it back into a folder name.
If, however, you are indeed working with simple version numbers, then using the
System.Versionclass (specifically, theParse()orTryParse()andToString()methods) would be a significantly more straightforward implementation.