string directory = project.Variables["folder"].Value;
string directoryTmp = directory + @"\folder\";
Directory.CreateDirectory(directoryTmp);
DirectoryInfo source = new DirectoryInfo(directory);
DirectoryInfo destin = new DirectoryInfo(directoryTmp);
foreach (var item in source.GetFiles())
{
string destinationPath = Path.Combine(directoryTmp, item.Name);
if (File.Exists(destinationPath))
{
string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(item.Name);
string randomString = Path.GetRandomFileName().Replace(".", "").Substring(0, 5);
string newFileName = $"{fileNameWithoutExtension}_{randomString}{Path.GetExtension(item.Name)}";
destinationPath = Path.Combine(directoryTmp, newFileName);
}
File.Move(item.FullName, destinationPath);
}