473,568 Members | 2,795 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Com pare(sourceFile Array[i].CreationTime,
cutoffTime) < 0)
{
string destinationFile Path = destinationDir. FullName
+ @"\" + sourceFileArray[i].Name;

this.targetShip pingLine.WriteT oLog
("DEBUG",destin ationFilePath, Convert.ToStrin g(File.Exists
(destinationFil ePath)));

if(!File.Exists (destinationFil ePath))
{
try
{
sourceFileArray[i].CopyTo(destina tionFilePath);
this.targetShip pingLine.WriteT oLog("LOGCOPY",
sourceFileArray[i].Name, "Sucessfull y copied log.");
}
catch (System.Excepti on e)
{
this.targetShip pingLine.WriteT oLog
(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 1451

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

25
7733
by: Xah Lee | last post by:
Python Doc Problem Example: gzip Xah Lee, 20050831 Today i need to use Python to compress/decompress gzip files. Since i've read the official Python tutorial 8 months ago, have spent 30 minutes with Python 3 times a week since, have 14 years of computing experience, 8 years in mathematical computing and 4 years in unix admin and perl, i...
12
8466
by: SJD | last post by:
I've just read Christoph Schittko's article on XmlSerializer: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnxmlnet/html/trblshtxsd.asp . . . and very informative it is too. I, too, am getting nasty FileNotFound exceptions. I've read, and digested the article, and I think I've found a bug -- it's difficult to track,...
8
3356
by: mytfein | last post by:
Hi Everyone, Background: Another department intends to ftp a .txt file from the mainframe, for me to process. The objective is to write a vb script that would be scheduled to run daily to process this .txt file. Goal: I am working on a vba script to:
3
26249
by: StGo | last post by:
How can i read/write file's custom attributs(like subject,author...) in C#??? Thanks :))
10
5876
by: Michael Murphy | last post by:
Hi, I have a Windows VB.Net app in which I need to keep files in one folder in sync with files in another folder. I have pasted the code below. Can anyone tell me why I end up with a folder with all the file names correct, but the length of each file is zero. Thanks for your help. Michael Public Function SyncFiles() As Integer Dim...
0
223
by: Tim Richardson | last post by:
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). ...
6
2333
by: TPJ | last post by:
Help me please, because I really don't get it. I think it's some stupid mistake I make, but I just can't find it. I have been thinking about it for three days so far and I still haven't found any solution. My code can be downloaded from here: http://www.tprimke.net/konto/PyObject-problem.tar.bz2. There are some scripts for GNU/Linux system...
3
19768
by: Lou | last post by:
Question: I can't seem to get file.exists(filename) to return true when I search using wildcards, and I know there's a file in that dir with that extension. here's the path dim yesno as boolean FileName = "D:\Documents and Settings\Lou\My Documents\Visual Studio Projects\Lucky7\Lucky7\bin\*.txt"
3
4161
by: trint | last post by:
How can I do this with my c# code with my website(because the file is there, but the code doesn't return it)?: if(File.Exists(String.Format("~/images/categories/{0}", sFileName)) return String.Format("~/images/categories/{0}", sFileName); else if(File.Exists(String.Format("~/images/products/{0}", sFileName)) return...
0
7604
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8117
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7660
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7962
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5498
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5217
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3651
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3631
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2101
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.