private void FileNameIncrement(string SourcePath, string DesignationPath)
{
DirectoryInfo dir = new DirectoryInfo(SourcePath);
string fileName = dir.Name;
string fileNamewithoutExtension = Path.GetFileNameWithoutExtension(DesignationPath + "\\" + fileName);
string fileExtention = Path.GetExtension(DesignationPath + "\\" + fileName);
string[] files = Directory.GetFiles(DesignationPath);
int count = files.Count(file => { return file.Contains(fileName); });
string newFileName = (count == 0) ? fileName : String.Format("{0} ({1})" + fileExtention, fileName, count +
1);
if (File.Exists(DesignationPath + "\\" + fileName))
{
File.Copy(SourcePath, DesignationPath + "\\" + newFileName);
}
else
{
File.Copy(SourcePath, DesignationPath + "\\" + fileName);
}
}
string OutputPath = @"C:\Documents and Settings\Naraayanan\My Documents\Downloads";
FileNameIncrement(textBox1.Text, OutputPath);
{
DirectoryInfo dir = new DirectoryInfo(SourcePath);
string fileName = dir.Name;
string fileNamewithoutExtension = Path.GetFileNameWithoutExtension(DesignationPath + "\\" + fileName);
string fileExtention = Path.GetExtension(DesignationPath + "\\" + fileName);
string[] files = Directory.GetFiles(DesignationPath);
int count = files.Count(file => { return file.Contains(fileName); });
string newFileName = (count == 0) ? fileName : String.Format("{0} ({1})" + fileExtention, fileName, count +
1);
if (File.Exists(DesignationPath + "\\" + fileName))
{
File.Copy(SourcePath, DesignationPath + "\\" + newFileName);
}
else
{
File.Copy(SourcePath, DesignationPath + "\\" + fileName);
}
}
string OutputPath = @"C:\Documents and Settings\Naraayanan\My Documents\Downloads";
FileNameIncrement(textBox1.Text, OutputPath);