4 SHARES Share Tweet

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:

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 Navigate to that directory and search for folders named sketch_****temp, such as sketch_180409 a97866199827863072temp . 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). Inside that folder, you should find a file such as sketch_180409a.java , 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:

import processing.core.*; import processing.data.*; import processing.event.*; import processing.opengl.*; import java.util.HashMap; import java.util.ArrayList; import java.io.File; import java.io.BufferedReader; import java.io.PrintWriter; import java.io.InputStream; import java.io.OutputStream; import java.io.IOException; public class sketch_180409a extends PApplet { public void setup() { println("Hello World 20190409"); //This was the only line in the Processing sketch noLoop(); } static public void main(String[] passedArgs) { String[] appletArgs = new String[] { "sketch_180409a" }; if (passedArgs != null) { PApplet.main(concat(appletArgs, passedArgs)); } else { PApplet.main(appletArgs); } } } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 import processing . core . * ; import processing . data . * ; import processing . event . * ; import processing . opengl . * ; import java . util . HashMap ; import java . util . ArrayList ; import java . io . File ; import java . io . BufferedReader ; import java . io . PrintWriter ; import java . io . InputStream ; import java . io . OutputStream ; import java . io . IOException ; public class sketch_180409a extends PApplet { public void setup ( ) { println ( "Hello World 20190409" ) ; //This was the only line in the Processing sketch noLoop ( ) ; } static public void main ( String [ ] passedArgs ) { String [ ] appletArgs = new String [ ] { "sketch_180409a" } ; if ( passedArgs != null ) { PApplet . main ( concat ( appletArgs , passedArgs ) ) ; } else { PApplet . main ( appletArgs ) ; } } }

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:

Stop using the computer and power it down On a separate device, make a Linux bootable USB drive Boot into Linux on the computer with the deleted Processing sketch 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. 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 Repeat step 5 until you see remnants of the program that may have been deleted. 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 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.