No, your code only partially works. It is creating 50 files, but they don't contain valid images. Also, if you run ls -al *.jpg
, you'll see that every file is 512 bytes long. The code is only writing the signature blocks out to the files.
After the first signature is found, all the data that follows is valid image data. The code needs to keep reading the data and adding it to the output file until the next signature block is found (at which point it should close the existing file and open a new one.)
You need to add code to handle the intermediate image data. There is none in the code now.
That's what is wrong with your code, and yes, it would be a duplicate because this is a very common problem. But that's ok. If you weren't able to recognize the problem, then you wouldn't understand why it has been seen before. ;-)
If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)