Recovering lost Processing sketches

This guide is for students who lost their code. If you are a parent of a student coding using Processing, make sure your child knows this is possible!

Processing saves every sketch you run in the temporary folder of your computer. For example, you can find your sketches in %TEMP% on Windows, and here’s a step by step guide:

  1. Open up the command prompt on windows (cmd.exe) and type echo %TEMP% to see where your current temporary directory is. For example, this might be C:\Users\username\AppData\Local\Temp on Windows 10
    • For users on MacOSX or Linux, the path will likely be /tmp or /var/tmp , or you can use the terminal (bash) command echo $TMPDIR to find the location
  2. Navigate to that directory and search for folders named sketch_****temp, such as sketch_180409a97866199827863072temp .  Notice that the underlined section in this example “sketch_180409“, corresponds to your sketch name (which also happens to include the date in YYMMDD format).
  3. Inside that folder, you should find a file such as , which should your code. Note that due to how Processing transpiles code into Java, this may have slight differences from what you actually typed. For example, a program with println(“Hello World 20180409”); will correspond to a much larger Java file with these contents:

If you can’t find the folder or your code, then it’s possible that your code is lost for good. However, we’ve had success recovering code that isn’t even visible in the temp folder using this more advanced strategy:

  1. Stop using the computer and power it down
  2. On a separate device, make a Linux bootable USB drive
  3. Boot into Linux on the computer with the deleted Processing sketch
  4. Determine the path to the drive equivalent to C:\ on Windows. This may be something like /dev/sda1 or /dev/sda2 . You may find it useful to use a program such as gparted to inspect drive sizes and partition sizes.
  5. Cat the contents of the raw drive/partition to the xdd hex parsing program, while grepping for code that you know exists within your program, such as via the command cat /dev/sdb1 | xdd | grep MyClass
  6. Repeat step 5 until you see remnants of the program that may have been deleted.
  7. Modify the code from step 5 to print lines before/after the matching line, e.g. cat /dev/sdb1 | xdd | grep -A 100 -B 100 MyClass will print 100 lines after and 100 lines before the matching line
  8. Modify the arguments for -A and -B until you recover the entire program

Good luck! Contact KTBYTE if you have further questions on code recovery.

Leave a Reply

Your email address will not be published. Required fields are marked *