I'm writing a file shredder and want to make sure that the shredder doesn't try to accidently delete itself. I know I can always keep a const string in the file code, but what if I decide someday to change the name of the file executable?
Second question:
Is it possible with c++ to check what if any programs are reading, writing to, or deleting my specified files?
Like the only way I was thinking of was if my c++ program was currently running and if I had a fstream object created and opened up to a file I wanted to protect that would prevent another program from reading and or deleting my file.
Is there anyway to get the name of the program that was trying to delete my file?
If in Windows, you can use GetModuleFilename() to get the name of the executable. As for knowing who has a certain file open, that's a good question. I am curious myself.