Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hooking my program with windows explorer's rename event

Tags:

c#

.net

file

io

Is there any way, in any language, to hook my program when a user renames a file?

For example: A user renames a file and presses enter (or clicks away) to confirm the rename action. BEFORE the file is actually renamed, my program "listens" to this event and pops up a message saying "Are you sure you want to rename C:\test\file.txt to C:\test\test.txt?".

I'm thinking/hoping this is possible with C++, C# or .NET.. But I don't have any clue where to look for.

like image 986
pek Avatar asked Aug 23 '08 21:08

pek


1 Answers

You can probably solve this by using the FileSystemWatcher class in .NET framework.

From the class remarks:

You can watch for renaming, deletion, or creation of files or directories. For example, to watch for renaming of text files, set the Filter property to "*.txt" and call the WaitForChanged method with a Renamed specified for its parameter.

like image 145
Riri Avatar answered Sep 21 '22 18:09

Riri