469,593 Members | 2,057 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,593 developers. It's quick & easy.

Problem with File.Exists() method.

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.
Jul 21 '05 #1
0 1232

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by StGo | last post: by
10 posts views Thread by Michael Murphy | last post: by
reply views Thread by Tim Richardson | last post: by
6 posts views Thread by TPJ | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.