I’m wondering how to modify my below code so that I may determine if a File has been duplicated based on the filename. For instance, a file name could look like this “Smith, #10 FINAL 08-20-2010.dwg” and if the file has been resubmitted it will then look like this “Smith, #10 FINAL 08-20-2010_1.dwg” or “Smith, #10 FINAL 08-20-2010_2.dwg”, etc… Notice the _1, _2, etc. I need to be able to determine if that File has a _1,_2,_3, etc and copy only the file with the greatest ending value (assumming it has one). I’m just lost on how to determine this. Many thanks..
//Now lets start searching the entire ARCHIVE folder/subfolders for a DWG that has
//this Well_Name and Actual_Date with FINAL in File Name...
DirectoryInfo myDir = new DirectoryInfo(@"C:\G-M");
//Collect the Final, Approved DWGs only...
var files = myDir.GetFileSystemInfos().Where(f => f.Name.Contains("FINAL") || f.Name.Contains(drow["Well_Name"].ToString()) || f.Name.Contains(drow["Actual_Date"].ToString()));
//Copy to directory...
foreach (FileInfo file in files)
{
//Lets loop through and check to see that the File has greatest value if it contains _1, _2, etc..
System.IO.File.Copy(file.FullName, @"C:\FINAL" + file, true);
}
This code should provide everything you will need:
Output is:
C:\Users\xxx\Desktop\a_1
C:\Users\xxx\Desktop\b_1000
C:\Users\xxx\Desktop\c