c# - Is there an easy way to add (#) to a filename when you find a duplicate filename? -


I am outputting files in C # and wanting to save the file by adding brackets and a number to the same name:

/ P>

  FooBar.xml FooBar (1) .xml FooBar (2) .xml ... FooBar (N) .xml  

Is there any easy way to do this In .NET? And is a special name for (#) ?

You only have to manually count and file name manipulation (proxy) code is filthy, But this is the basic algorithm. Convert it to your needs.

  var filenameFormat = "FooBar {0} .xml"; Var filename = string.Format (filenameFormat, ""); Int i = 1; While (file example (filename)) filename = string.Format (filenameFormat, "(" + (i ++) + ")"); File name back;  

If you can participate with it, then you can always attack the datetime. Now you do this for the temporary files anyway in your preferred format.


Comments

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -