467,212 Members | 1,207 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

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

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
  • viewed: 5517
Share:
3 Replies
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by richardclay09@yahoo.co.uk | last post: by
2 posts views Thread by Lebplaya | last post: by
12 posts views Thread by Anders Eriksson | last post: by
1 post views Thread by Randy | last post: by
5 posts views Thread by Alan Little | last post: by
3 posts views Thread by jsurkin@gmail.com | last post: by
13 posts views Thread by rohit | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.