How to check if there is a new file in a folder?

L

Lakesider

Dear NG,

I want to check if there is a new file in a specific folder. If I copy
a big file into the folder (while the programm is running), I already
can access it. There is the problem: how can I check if a file is
already copied or not!? How do I know if a file is "ready" for use?

I open the CheckMyFolder function once a second:

public void CheckMyFolder()
....
files = directory.GetFiles();

foreach (FileInfo f in files)
{
// read the whole thing, do something
}
....
}

Thank you very much for your help

Rudi
 
K

Kevin Spencer

Use the System.IO.FileSystemWatcher class.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
A watched clock never boils.
 
L

Lakesider

Thank you,

but which Event is the right for me?
It should fire if a large file is beeing copied successfully to my
folder.

Thank you

Rudi
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top