473,700 Members | 2,582 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(d ir);
FileInfo[] rgFiles = di.GetFiles(typ e);

foreach(FileInf o fi in rgFiles)
{
if (fi.LastAccessT ime != fi.CreationTime )
{
string key = fi.Name.ToUpper () +
fi.Length.ToStr ing().ToUpper() +fi.CreationTim e.ToString("yyy yMMdd").ToUp
per();
fileList[key] = fi;
}
}

*** Sent via Developersdex http://www.developersdex.com ***
Apr 3 '06 #1
3 5691
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******@pland atamgmt.com> wrote in message
news:Or******** ******@TK2MSFTN GP11.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(d ir);
FileInfo[] rgFiles = di.GetFiles(typ e);

foreach(FileInf o fi in rgFiles)
{
if (fi.LastAccessT ime != fi.CreationTime )
{
string key = fi.Name.ToUpper () +
fi.Length.ToStr ing().ToUpper() +fi.CreationTim e.ToString("yyy yMMdd").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******@pland atamgmt.com> wrote in message
news:Or******** ******@TK2MSFTN GP11.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(d ir);
FileInfo[] rgFiles = di.GetFiles(typ e);

foreach(FileInf o fi in rgFiles)
{
if (fi.LastAccessT ime != fi.CreationTime )
{
string key = fi.Name.ToUpper () +
fi.Length.ToStr ing().ToUpper() +fi.CreationTim e.ToString("yyy yMMdd").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*********@ho tmail.com> wrote in message
news:Od******** ******@TK2MSFTN GP14.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******@pland atamgmt.com> wrote in message
| news:Or******** ******@TK2MSFTN GP11.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(d ir);
| > FileInfo[] rgFiles = di.GetFiles(typ e);
| >
| > foreach(FileInf o fi in rgFiles)
| > {
| > if (fi.LastAccessT ime != fi.CreationTime )
| > {
| > string key = fi.Name.ToUpper () +
| > fi.Length.ToStr ing().ToUpper() +fi.CreationTim e.ToString("yyy yMMdd").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
1360
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
1889
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 parent upon execution of each program. I need the parent to print out a message upon successful completion of the exec statements. Since the children have to run in parallel, i cannot run the first child and wait for completion ... they must all be run...
12
15904
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. The problem is that I don't know when the file is complete when using Explorer copy or move. I have tried to use FileIOPermission but I always get that the file is
1
1717
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 ---------------------------------------------------------- ** SPEED ** RETENTION ** COMPLETION ** ANONYMITY ** ---------------------------------------------------------- http://www.usenet.com
5
3206
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
2585
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 orders in all batches ever submitted by that affiliate. I'm trying to figure out the most efficient way to check the uniqueness of the order ID. Order data is being submitted to Zen Cart, and also stored in custom tables. I have created a unique...
3
8791
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 the work is completed, along with a date text box to indicate when the work was completed. There is also a check box and corresponding date field in the main form to indicate when the entire request is completed. I'm trying to create an event...
13
1062
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 command will set a the second file as a link to the first file rather than an independent copy of the first file. (Windows has the CopyFile command but I didn't find anything that would work under UNIX)
13
10414
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 set of integers stored in an array.It would be a great help if you could provide some code for it.I tried the function fscanf but by that I am able to read only the first integer of the text file.Please help me.
0
8647
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9217
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8974
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
8926
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7813
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5903
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3092
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
2
2392
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2030
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.