473,327 Members | 2,065 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

How to check for copy file completion

Riddle me this... I have an app which listens to a windows folder for
files to appear and then processes the file based on the file format. My
question is if a really big file appears in the folder (say over 20 G)
then it takes more than 20 minutes for the file to be copied there. As
my listener job looks in the folder every 30 seconds I don't want to
process the file until the whole file is there - if you get what I mean.
The only way I think I have found to ensure that a file is a whole file
and not in the process of loading into the folder is to compare the
fileInfo LastAccessTime to the fileInfo CreationTime (below). I'm not
sure if this is really the correct way to go. Any one else come across
this problem or any ideas?

Hashtable fileList = new Hashtable();
DirectoryInfo di = new DirectoryInfo(dir);
FileInfo[] rgFiles = di.GetFiles(type);

foreach(FileInfo fi in rgFiles)
{
if (fi.LastAccessTime != fi.CreationTime)
{
string key = fi.Name.ToUpper() +
fi.Length.ToString().ToUpper()+fi.CreationTime.ToS tring("yyyyMMdd").ToUp
per();
fileList[key] = fi;
}
}

*** Sent via Developersdex http://www.developersdex.com ***
Apr 3 '06 #1
3 5681
You should check the FileWatcher class.. I have not used it.. but you may
find something useful there...

http://www.codeproject.com/csharp/Fi...herWrapper.asp

Vijay

"booksnore" <sa******@plandatamgmt.com> wrote in message
news:Or**************@TK2MSFTNGP11.phx.gbl...
Riddle me this... I have an app which listens to a windows folder for
files to appear and then processes the file based on the file format. My
question is if a really big file appears in the folder (say over 20 G)
then it takes more than 20 minutes for the file to be copied there. As
my listener job looks in the folder every 30 seconds I don't want to
process the file until the whole file is there - if you get what I mean.
The only way I think I have found to ensure that a file is a whole file
and not in the process of loading into the folder is to compare the
fileInfo LastAccessTime to the fileInfo CreationTime (below). I'm not
sure if this is really the correct way to go. Any one else come across
this problem or any ideas?

Hashtable fileList = new Hashtable();
DirectoryInfo di = new DirectoryInfo(dir);
FileInfo[] rgFiles = di.GetFiles(type);

foreach(FileInfo fi in rgFiles)
{
if (fi.LastAccessTime != fi.CreationTime)
{
string key = fi.Name.ToUpper() +
fi.Length.ToString().ToUpper()+fi.CreationTime.ToS tring("yyyyMMdd").ToUp
per();
fileList[key] = fi;
}
}

*** Sent via Developersdex http://www.developersdex.com ***

Apr 3 '06 #2
While the file is being written to disk, there would be a lock on it by the
writer. So you would not be able to access it and you will get IOException
thrown at you. You can check for this exception.

"booksnore" <sa******@plandatamgmt.com> wrote in message
news:Or**************@TK2MSFTNGP11.phx.gbl...
Riddle me this... I have an app which listens to a windows folder for
files to appear and then processes the file based on the file format. My
question is if a really big file appears in the folder (say over 20 G)
then it takes more than 20 minutes for the file to be copied there. As
my listener job looks in the folder every 30 seconds I don't want to
process the file until the whole file is there - if you get what I mean.
The only way I think I have found to ensure that a file is a whole file
and not in the process of loading into the folder is to compare the
fileInfo LastAccessTime to the fileInfo CreationTime (below). I'm not
sure if this is really the correct way to go. Any one else come across
this problem or any ideas?

Hashtable fileList = new Hashtable();
DirectoryInfo di = new DirectoryInfo(dir);
FileInfo[] rgFiles = di.GetFiles(type);

foreach(FileInfo fi in rgFiles)
{
if (fi.LastAccessTime != fi.CreationTime)
{
string key = fi.Name.ToUpper() +
fi.Length.ToString().ToUpper()+fi.CreationTime.ToS tring("yyyyMMdd").ToUp
per();
fileList[key] = fi;
}
}

*** Sent via Developersdex http://www.developersdex.com ***

Apr 3 '06 #3
I think maybe you need to make FileShare.None, FileMode.Write for this to
work as expected. But that would seem to be a good way to go. Another way
used in the past is to download to a temp file, then when done, rename the
file and the poll loop will then "see" the file.

--
William Stacey [MVP]

"Winista" <na*********@hotmail.com> wrote in message
news:Od**************@TK2MSFTNGP14.phx.gbl...
| While the file is being written to disk, there would be a lock on it by
the
| writer. So you would not be able to access it and you will get IOException
| thrown at you. You can check for this exception.
|
| "booksnore" <sa******@plandatamgmt.com> wrote in message
| news:Or**************@TK2MSFTNGP11.phx.gbl...
| > Riddle me this... I have an app which listens to a windows folder for
| > files to appear and then processes the file based on the file format. My
| > question is if a really big file appears in the folder (say over 20 G)
| > then it takes more than 20 minutes for the file to be copied there. As
| > my listener job looks in the folder every 30 seconds I don't want to
| > process the file until the whole file is there - if you get what I mean.
| > The only way I think I have found to ensure that a file is a whole file
| > and not in the process of loading into the folder is to compare the
| > fileInfo LastAccessTime to the fileInfo CreationTime (below). I'm not
| > sure if this is really the correct way to go. Any one else come across
| > this problem or any ideas?
| >
| > Hashtable fileList = new Hashtable();
| > DirectoryInfo di = new DirectoryInfo(dir);
| > FileInfo[] rgFiles = di.GetFiles(type);
| >
| > foreach(FileInfo fi in rgFiles)
| > {
| > if (fi.LastAccessTime != fi.CreationTime)
| > {
| > string key = fi.Name.ToUpper() +
| > fi.Length.ToString().ToUpper()+fi.CreationTime.ToS tring("yyyyMMdd").ToUp
| > per();
| > fileList[key] = fi;
| > }
| > }
| >
| >
| >
| > *** Sent via Developersdex http://www.developersdex.com ***
|
|
Apr 3 '06 #4

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

Similar topics

10
by: richardclay09 | last post by:
The output of this: #include <iostream> #include <vector> using namespace std; struct X { int i; X(const X& x) : i(x.i) { cout << "ctor copy: " << i << endl;
2
by: Lebplaya | last post by:
Ok ... heres my situation. I need to run 4 child processes in parallel. each child process will exececute a different program. How would i go about sending the PID of the child back to the...
12
by: Anders Eriksson | last post by:
Hello! I'm trying to create a program that will watch a directory and when a file is created print that file. I have used FileSystemWatcher for watching the directory and I get an created event....
1
by: Randy | last post by:
I want to copy an existing file into a new one. How can I program this? Posted Via Usenet.com Premium Usenet Newsgroup Services ---------------------------------------------------------- **...
5
by: Julian Milano | last post by:
I want to copy a file from one PC to another using DotNet and would like to time the operation- how do I do it?
5
by: Alan Little | last post by:
I have affiliates submitting batches of anywhere from 10 to several hundred orders. Each order in the batch must include an order ID, originated by the affiliate, which must be unique across all...
3
by: jsurkin | last post by:
I have a form that lists a single work request, with an attached continuous subform that lists specific items that are part of the request. Each item in the subform has a check box to indicate when...
13
by: Avi | last post by:
Hi, Is there a UNIX C system command that will let me copy a file? I am looking for something similar to "cp" that can be called within a C program. I know of the "link" system call but this...
13
by: rohit | last post by:
Hi All, I am new to C language.I want to read integers from a text file and want to do some operation in the main program.To be more specific I need to multiply each of these integers with another...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.