We help IT Professionals succeed at work.

How to find or get the file name ...?

chenwei
chenwei asked
on
In my program I use the FindFirstChangeNotification to detect if a file is moved to a directory or not. But how can I get the file name? Further, if I just consider files with contern mask such as .TXT file or .DOC file etc. how can I do that?
Comment
Watch Question

Commented:
With FindFirstChangeNotification you can't automatically get the file name. This API simply doesn't support it. You have to build a file list in memory before calling the API, then build a new file list when an event was triggered and then compare the file lists to find out yourself, what exactly has changed.

Another solution would be to use ReadDirectoryChangesW, this API tells you also the file name, but it's only available in winNT based systems (NT4, 2k, XP).

Finally there's undocumented functionality available for win9x, see here:

http://www.geocities.com/SiliconValley/4942/index.html

Regards, Madshi.

Author

Commented:
Thanks a lot. I just use NT. I will have a try and give you the answer later.

Author

Commented:
Hi, I am going to use the ReadDirectoryChangesW() function. But I can't open the sample file since I haven't the CD. Do you have an example for that?
Commented:
Why don't you search on google?   :-)

http://www.google.de/search?q=ReadDirectoryChangesW&hl=de&meta=

The second link directly leads to a full demo project:

http://www.codeproject.com/file/directorychangewatcher.asp

Regards, Madshi.

Author

Commented:
Thanks a lot. Sure I know google. But I don't know one can get so many information there. :-)

I've put up another question, could you answer it? :-)

Commented:
Sorry, I'm a Delphi programmer, thus I can't help you with the other question, it's a purely C++ related one...

Explore More ContentExplore courses, solutions, and other research materials related to this topic.