I want to create a console application that detects when I insert a usb on my pc and then it copies itself to that usb storage device. It also has to detect if an usb storage device is already connected and copies itself to there.
I found an example with GetLogicalDriveStrings but it lists the all the drives on the pc, I need it to be just the usb storage devices.
I could probably come up with a solution where I would search for all the letters like this:
1 2 3 4 5 6 7 8
char* letter = 'c';
while (letter++ != 'z;){
// check if it exists -> if(exists("e:/")
}
But that seems to me a very ugly solution. Please help.
Edit: my current environment is codeblocks20.03 on windows10
You use a function called setupgetclassdevs(w or a) to get a device infoset. Then use setupdienumdeviceinfo to actually pull the information out of the device info set. I actually have some example code here. https://www.cplusplus.com/forum/beginner/275043/
Once the handle to the drive is open you can use read and write operations on it.
Correction. I guess it's possible once you have the device location to do a filemove operation. The above is apparently only for i/o.
Id also like to add that im not a big fan of the message only window solution. I was playing around with that earlier this week and it only seems to receive the notifications if it's the focus of the desktop or active. There maybe a solution to that problem but im thinking it would probably be more of a sure thing to continuously poll the devices in the system that are a specific type and compare it to the initial or previous poll to see if another (or a device) has popped up that meets the requirements.