Reading First Few Bytes of Every File on a Drive
Hi! Hoping someone can help. My Python programing is a bit rusty.
I am having an issue where my computer is replacing file data with empty data after a cut/paste or a save. I’m not sure of the cause — my primary objective at the moment is quantifying the damage and protecting my files.
The files look normal in Windows Explorer, except they will not open like they should. Upon opening in NotePad, it is revealed that all data in the file has been completely replaced with what appears to be whitespace, resulting in an empty file that appears to be the same size as the original. I cannot possibly test and check every file manually.
What I would like help with is writing a Python script that cycles through every file on a drive to pull the first several bytes from each file and compare those bytes to a string of the aforementioned whitespace. If there is a match, add the file path to a running list in a *.txt file.
I don’t think this is an especially complex script, but, as I said earlier, I’m pretty rusty. With a solid start, I can get it the rest of the way to doing what I want.
Any help would be appreciated. 🙂