By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,889 Members | 1,373 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,889 IT Pros & Developers. It's quick & easy.

How to check for copy file completion

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.