I am trying to get some of the zip files from a specific folder to my destination folder which contains a specific date range added in the file name so for example zip file contains a name such as FE1_ABS_202404240600.zip, FE1_ABS_202404240601.zip, FE1_ABS_202404240610.zip, etc
Now I have written a code which does extracts the file but after about 5 or 6 copy. It fails. Error message contains that ” the file ‘[sourcepath]FE1_ABS_202404240600.zip’ already exist.
I am unsure how can I remove this issue and copy all file between such date range
public static void getFilesNames() {
string startDate = "04/24/2024";
string endDate = "06/03/2024";
DateTime tmpDate1 = DateTime.ParseExact(startDate, "MM/dd/yyyy", null);
DateTime tmpDate2 = DateTime.ParseExact(endDate, "MM/dd/yyyy", null);
string startdt = tmpDate1.ToString("yyyyMMdd");
string enddt = tmpDate2.ToString("yyyyMMdd");
DateTime dtStart = DateTime.Parse(startDate);
DateTime dtEnd = DateTime.Parse(endDate);
string sourcePath = @ "E:ReceivedFile";
string destPath = @ " E:ProcessedFile";
do {
string partialName = "ABS";
DirectoryInfo hdDirectoryInWhichToSearch = new DirectoryInfo(sourcePath);
FileInfo[] filesInDir = hdDirectoryInWhichToSearch.GetFiles("*" + partialName + "_" + startdt + "*.zip*");
foreach(FileInfo foreachPath in filesInDir) {
string fullName = foreachPath.FullName;
File.Copy(Path.Combine(sourcePath, foreachPath.ToString()), Path.Combine(destPath, foreachPath.ToString()));
}
} while (dtStart < dtEnd);
}
Checked if I have my duplicate zip files but seems I have unique files in my source. So why showing duplicate file error?