i have a window form in which display all directories in listview .for copying files if a file already exist its copies it again appending file.txt(1) with it.and if this is again copied file.txt(2)
string fileNameOnly = Path.GetFileNameWithoutExtension(file);
string extension = Path.GetExtension(file);
string pathDir = Path.GetDirectoryName(file);
string tempFileName = string.Format("{0}({1})", fileNameOnly, count++);
string newfileName = Path.Combine(pathDir, tempFileName + extension);
if (MessageBox.Show(file + "is already exists\r\nDo you want to copy Again?",
"Overwrite", MessageBoxButtons.OKCancel,
MessageBoxIcon.Asterisk) == DialogResult.OK)
{
// Directory.Move(file, Path.Combine(new string[] { DestinationFolder, newfileName }));
File.Copy(file, Path.Combine(new string[] { DestinationFolder, newfileName }));
MessageBox.Show("File Copied");
but the problem is this that when i copy the files again and again the pattern is like file.txt(1)/file.txt(1)(1)/file.txt(1)(1)(1)/ it doesnt increment the number inside ..i dont know how to increment the count every time i copy..can anybody tell what im doing wrong