Recover an .ino file

Yesterday I made big changes to my .ino file, this compiled and uploaded to the board successfully.
Today, on restarting my computer I find that the .ino file is the previous unchanged version, so seemingly the IDE failed to save the changes when I uploaded. Is the any hope of recovering the latest .ino file, could it have been saved in some obscure location?

That depends on what setting you have in the preferences file.

If you have it set for save and verify and did not change the file name then it changed your original to the one you say is bad.

If you dont have save and verify then the original should be intact

Its a lesson we all learned mostly the hard way…
I always add V1, V2 etc at the end of any changed sketch and add WORKING COPY if its one I dont want to change

Ballscrewbob:
Its a lesson we all learned mostly the hard way..
I always add V1, V2 etc at the end of any changed sketch and add WORKING COPY if its one I dont want to change

Why not just use github or other source control tool?

Github is a learning curve for a lot of people and certainly not so easy when you have your first ever encounter with programming and just want to run before you can walk.
That said...

Once people realise all the best libs are on GH and settle into programming Arduinos (or other things) it becomes more natural.

For some like me I just became more used to doing versions OFF web.

RodMoody:
could it have been saved in some obscure location?

Which version of the Arduino IDE are you using?

Ballscrewbob:
For some like me I just became more used to doing versions OFF web.

You can use git or GitHub desktop with repositories stored on your computer. There's no need to upload them to the GitHub site if you don't want to. I agree that expecting the average Arduino beginner to also take on learning how to use a source control tool will probably be counterproductive but once you get to your level it's so worth the effort.

I don't think that you lost the changed sketch as Arduino IDE always save the last sketch as default. Can you go to File -> Preferences and look at whether "Save when verifying or uploading" is tick or not. If it's tick (as default), your changed sketch could be somewhere, try finding it gain. Good luck

Wow, this is my first time on this forum, and I'm well impressed with all the responses, my sincere thanks to all who responded. As it turns out I found the solution to the problem myself:- The Arduino IDE had saved my source.ino file exactly as it should. The problem was that I had run a System Restore and that restored my source.ino file back to its state when the restore point was set. I proved this resolved the problem by undoing the System Restore, retrieving my latest version of source.ino, saving it to an external driven, re-invoked the System Restore (I needed to do this for other unrelated reasons) and then copied my source.ino file from the external drive back to its place on the PC. What amazes me is that System Restore would mess with my source.ino file. It’s "my data" and has nothing to do with the Windows operating system. Even if it was compiled it could not be executed by Windows! I’m using Windows 10 and my sourse.ino is held in a subfolder of Documents, Arduino IDE is 1.6.6.

I have just had exactly the same problem with Win7. Somehow .ino files are seen as system files.

Fortunately, I found a good tip somewhere else on this forum that saved me a lot of work:

Went to the %temp% folder and found the temporary cpp file created during the last compilation, still intact. I opened it with Wordpad and was able to copy/paste my latest changes into the obsolete .ino file.

I hope this helps.

i opened %temp% folder but i can only find files that can not be opened by the IDE :

theFileIwant_ino.cpp.hex
theFileIwant_ino.cpp.eep
theFileIwant_ino.cpp.o
theFileIwant_ino.cpp.d
theFileIwant_ino.cpp.elf

but can not fine theFileIwant.ino

what am i missing?

You are missing having read the forum rules / stickies at the top of each section.

If you deleted your sketch then you need to check your OS waste bin to get it back.
The files you see in the temp folders are usually pre-compiled and ancillary files and not sketches.

alaherma:
i opened %temp% folder but i can only find files that can not be opened by the IDE :

theFileIwant_ino.cpp.hex
theFileIwant_ino.cpp.eep
theFileIwant_ino.cpp.o
theFileIwant_ino.cpp.d
theFileIwant_ino.cpp.elf

This is promising. In that same folder where you see those files, there should be a subfolder named sketch. In that folder, you should find a file named theFileIwant.ino.cpp. That will be a little different from your sketch, but it will be quite easy to remove the extra stuff that was added in during sketch preprocessing, and I can help you with that.

In some earlier versions of the Arduino IDE, the file was in different places or named differently. The important thing is to find the file that starts with theFileIwant and ends with .cpp.

Be aware that when you exit the Arduino IDE, it will try to delete the temporary build folder. Sometimes it ends up leaving it behind in your temp folder, but I would avoid exiting the Arduino IDE until you have determined whether you can recover the sketch file. At least on Windows, the way the Arduino IDE does the deletion will be permanent and you will not find it in the Recycle Bin. I suspect the same holds true for the other OS.