Hi.
I have an application that moves files to a folder every 20 minutes. My users told me that there are bound to be duplicate files and that they usually handle the duplicates by manually adding letters to the files:
Microsoft-IE8-23809-02.edi
at 10am this comes in again and becomes
Microsoft-IE8-23809-02_A.edi
at 10:20 the same file is repostd and then renamed:
Microsoft-IE8-23809-02_B.edi
I have the following code for the move function. If the file already exists in the destination folder, then it should be renamed in the source folder and then moved to the destination folder with the new name? How can I make sure that the letters are recognized and auto-incremented and then properly moved? When I add the move function, I get the error:
Current Code
Error
I have an application that moves files to a folder every 20 minutes. My users told me that there are bound to be duplicate files and that they usually handle the duplicates by manually adding letters to the files:
Microsoft-IE8-23809-02.edi
at 10am this comes in again and becomes
Microsoft-IE8-23809-02_A.edi
at 10:20 the same file is repostd and then renamed:
Microsoft-IE8-23809-02_B.edi
I have the following code for the move function. If the file already exists in the destination folder, then it should be renamed in the source folder and then moved to the destination folder with the new name? How can I make sure that the letters are recognized and auto-incremented and then properly moved? When I add the move function, I get the error:
Code:
Process is being used by another.
Current Code
Code:
foreach (string myfile in files)
{
//Grab Basic file information
filename = Path.GetFileName(myfile);
fu = new FileInfo(filename);
string afile = fu.Name;
String dest = Path.Combine(targetPathDir, filename);
String sou = Path.Combine(sourcePathDir, filename);
String nTarget = Path.Combine(targetPathDir, filename);
String nDupe = Path.Combine(dupePathDir, filename);
String nRnme = Path.Combine(renmeDir, filename);
char alpha = 'A';
alpha = (char)((byte)alpha + 1);
if (File.Exists(dest))
{
while (true)
{
string extension = Path.GetExtension(myfile);
string fname = myfile.Replace(extension, String.Empty);
string newfile = fname + "_" + alpha.ToString() + extension;
File.Copy(myfile, newfile);
moveFile dMove = new moveFile();
dMove.moveAll(myfile, nRnme);
}
}
else
{
moveFile nMove = new moveFile();
nMove.moveAll(myfile, nDupe);
}
}
Error
Code:
System.IO.IOException: The file 'L:\EDI_TG\Deal_18177-56_B.edi' already exists.