We can find the change in directory by using the FindFirstChangeNotification()
and FindNextChangeNotification()
functions like :
FindFirstChangeNotification(
lpDir, // directory to watch
FALSE, // do not watch subtree
FILE_NOTIFY_CHANGE_FILE_NAME); // watch file name changes
But in Windows there is no actual path for media portable devices like Android phones, camera, etc. Then how can we track the changes (create,copy,delete,rename) done on these devices in C++?
These media devices only exist at the shell level, they do not allow direct access to their filesystem (and even if they did, it might be ext3 or some other filesystem not supported by Windows). You cannot use FindFirstChangeNotification
and other functions in kernel32, you must use the functions in shell32 and shlwapi that supports IShellItem, IShellFolder and PIDLs.
To create a PIDL you can call SHParseDisplayName
if you know the path (shell:::{something}\{something}
) or SHGetDesktopFolder
+ IShellFolder::EnumObjects
to walk the entire shell namespace.
Sometimes it is possible to find the shell: path by right clicking the item in the Explorer breadcrumb-bar and selecting "Copy address".
When you have an absolute PIDL to the device folder you can call SHChangeNotifyRegister
.