I am attempting to copy some files from one machine to
another. I am having difficulty with the File.Exists()
in the code below. The program enumerates the files in a
directory, checks them against a cuttoff DateTime, and
copies them if thet do not already exist. All progress
is written to a log (a snippet is included below the
code). The File.Exists() method returns false even when
the file does in fact exist. Have I coded this
incorrectly?
P.S. This code seems to work on my XP test box, but when
I copy it to the production machine running Windows 2000
server, it fails.
CODE SNIPPET:
for(int i=0; i < sourceFileArray.Length; i++)
{
if(DateTime.Compare(sourceFileArray[i].CreationTime,
cutoffTime) < 0)
{
string destinationFilePath = destinationDir.FullName
+ @"\" + sourceFileArray[i].Name;
this.targetShippingLine.WriteToLog
("DEBUG",destinationFilePath, Convert.ToString(File.Exists
(destinationFilePath)));
if(!File.Exists(destinationFilePath))
{
try
{
sourceFileArray[i].CopyTo(destinationFilePath);
this.targetShippingLine.WriteToLog("LOGCOPY",
sourceFileArray[i].Name, "Sucessfully copied log.");
}
catch (System.Exception e)
{
this.targetShippingLine.WriteToLog
(true, "LOGCOPY", sourceFileArray[i].Name, e.Message);
}
}
}
}
LOG SNIPPET:
DEBUG <some filepath> 10/20/2003 1:55:53 PM
False
ERROR LOGCOPY <some filepath> 10/20/2003 1:55:53 PM
The file <some filepath> already exists.