Windows Event when files are added to a folder

B

Benry

Without having a reference to a specific folder, is there a way that
Windows fires an event when files in a folder are modified? I'm using
C++.NET 2.0 for programming a service, and would like this to be the
starting point. I have a shared folder which is the login folder of
an FTP server. Once a file has been uploaded, I want windows kernel
to interrupt/trigger and start the process.

I know I can poll the folder, but I would like something less
processor intensive.

Thanks!
Benry
 
B

Bruno van Dooren [MVP - VC++]

Without having a reference to a specific folder, is there a way that
Windows fires an event when files in a folder are modified?

Well these questions should go in one of the platform SDK groups. This is a
C++ group.
I'm using
C++.NET 2.0 for programming a service, and would like this to be the
starting point. I have a shared folder which is the login folder of
an FTP server. Once a file has been uploaded, I want windows kernel
to interrupt/trigger and start the process.

This is the wrong approach. the service should already be running. Otherwise
you will have a lot of overhead if the service has to be started and stopped
for each file.
I know I can poll the folder, but I would like something less
processor intensive.

Have a look at FindFirstChangeNotification and family.
You can get notifications for creating / renaming files etc.
Be sure that your have some form of synchronization to prevent problems in
case you are processing files when your service receives the shutdown
command and things like that.

And of course, you should scan the folder at startup to make sure that there
is nothing there that got added when your service was not yet running.
 
B

Benry

Bruno,

I appreciate your comments, but would like to clarify some things as
well as ask a question. Please see my comments below.
Well these questions should go in one of the platform SDK groups. This is a
C++ group.

Then I'm confused as to why this group is named M
$.public.dotnet.languages.vc, when I could just go to comp.languages.c+
+ to ask specific C++ questions. There's a "dotnet" part of the name
of this newgroup that makes your comment confusing. .NET is a
framework, which includes answers to the question I asked. Why is
this just a C++ group when "dotnet" is in the title?
This is the wrong approach. the service should already be running. Otherwise
you will have a lot of overhead if the service has to be started and stopped
for each file.


Have a look at FindFirstChangeNotification and family.
You can get notifications for creating / renaming files etc.
Be sure that your have some form of synchronization to prevent problems in
case you are processing files when your service receives the shutdown
command and things like that.

What works is System.IO.FileSystemWatcher (I'm sorry this isn't a C++
response if I'm not allowed to talk about .NET). It's included in the
default Toolbox for VC++2005 Express. I tested it, and it is working
for my application so far. I can use this control to clean up files
that don't belong as well as to take care of incoming FTP files.
And of course, you should scan the folder at startup to make sure that there
is nothing there that got added when your service was not yet running.

Yes. This response had nothing to do with my question, but I
appreciate the comment.

Thanks again,
Benry
 
B

Ben Voigt [C++ MVP]

Benry said:
Bruno,

I appreciate your comments, but would like to clarify some things as
well as ask a question. Please see my comments below.


Then I'm confused as to why this group is named M
$.public.dotnet.languages.vc, when I could just go to comp.languages.c+
+ to ask specific C++ questions. There's a "dotnet" part of the name
of this newgroup that makes your comment confusing. .NET is a
framework, which includes answers to the question I asked. Why is
this just a C++ group when "dotnet" is in the title?

Because Microsoft C++ isn't the same as ANSI/ISO standard C++. This group
is about Microsoft's version of the C++ language, and especially the dotnet
part of Microsoft's compiler, C++/CLI. Some of the questions here might
address standard C++, and some might be Microsoft-specific.

At the same time, usually you would have gotten a pointer to
"FindFirstChangeNotification" and "ReadDirectoryChanges" functions.
 

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