Sujeet Raman

Sujeet Raman

  • 812
  • 915
  • 336.3k

How to append a number in to a file name and make it Unique?

Apr 19 2022 7:30 AM

Hi,

I have to copy some .txt files in to a different location.But the issue is i am unable to paste those files due to same name.I am getting those .txt files from different folder.I need to append a number to make .txt file unique and paste in to different location.My current code doesnt allow this.How can i do this?

foreach (var file in Directory.EnumerateFiles(extractPathForCurrentZip, "*.txt"))
{
    File.Copy(file, DestinationFoldername+ Path.GetFileName(file));
}

Answers (1)