How to check duplicate files while copying

Posted by Chaithragm under C# on 5/20/2013 | Points: 10 | Views : 1908 | Status : [Member] | Replies : 2
im using this code...it will copy files from one folder to another folder while copying it will not check for duplicate files
it has to check the duplicate files in the destination folder and reject the duplicate files

public static void CopyDirectory(DirectoryInfo source, DirectoryInfo destination)
{
try
{

if (!destination.Exists)
{
destination.Create();
}
//


//
// Copy all files.
FileInfo[] files = source.GetFiles();

foreach (FileInfo file in files)
{
file.CopyTo(Path.Combine(destination.FullName,
file.Name));

}

// Process subdirectories.
DirectoryInfo[] dirs = source.GetDirectories();
foreach (DirectoryInfo dir in dirs)
{
// Get destination directory.
string destinationDir = Path.Combine(destination.FullName, dir.Name);

// Call CopyDirectory() recursively.
CopyDirectory(dir, new DirectoryInfo(destinationDir));
}
}
catch (Exception ec)
{
MessageBox.Show(ec.ToString());
}
}




Responses

Posted by: Blessyjees on: 5/20/2013 [Member] Bronze | Points: 25

Up
0
Down
hi,

try like this
string source=String.Empty;
string destination=String.Empty;
foreach (string currentFile in Directory.GetFiles(workingDir))
{
source= //generate the source path
destination=//generate the destination path
File.Move(source, destination);
}

Blessy Baby
Digitalmesh Softech pvt Ltd
https://blessybaby.wordpress.com/

Chaithragm, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Praks on: 6/3/2013 [Member] Starter | Points: 25

Up
0
Down
Hi, if u only want to copy files from one folder to another folder you can use
POSTBUILD EVENT'S

like :
copy "$(SolutionDir)\..\References\Test\" "$(ProjectDir)"

Chaithragm, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response