Does C# have any functions to produce a new name for a copied item ?
For example , if I have a string called "Folder" , I need a function to produce a string "Copy of Folder".... and given the string "Copy of Folder" the function should produce "Copy of Folder (1)" and so on ....
You can write a loop, like this:
string baseName = @"C:\Parent\Copy of Folder", actualName = baseName;
int index = 0;
while(File.Exists(actualName) || Directory.Exists(actualName))
actualName = baseName + " (" + (++index) + ")";
Depending on your use-case, you should probably put this in a static
utility method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With