My code lost. Help!

while I was editing my code for my application, i saved my code but just after saving it my computer’s power went off, i restarted my computer and my application’s file was there but when i opened it with the processing editor the code blank, there is nothing there. Not even the previously saved versions of my code. But i noticed my file size is the same, i am hoping i can recover my code somehow. Thanks in advance!.

Hm.

Look in your temp folder

These are temporary files

sorry i am new to this, can you tell me where the temp folder is located?

3 Likes

Note that the contents of the Java file will need to be minimally translated back into your sketch–it is the same code, but preprocessed (color becomes int, things move between setup and settings, functions have prefixess etc)

Also note that the location of temp files is different depending on your operating system.

4 Likes

how do i search for my fill in the temp folder?

I have one program to search the file names and I have one sketch to search the file content

here is the latter / 2nd one:

Please make sure to set the data inside the ****** section at the beginning of the sketch correctly !!!

where it says // alter these values:


// SEARCH FOR FILE CONTENT
// containing searchPhrase

// user selects folder, all sub-folders are searched

//**************************************************************
// alter these values:
String searchPhrase      = "fill"; // "MENGER";  // search this 
boolean ALL_UPPER_CASE   = false;  // true = not case-sensitive 

boolean CHECK_ONLY_FILES_CONTAINING = true; // we can search for a certain file type only e.g. ".pde"
String ALLOWED_ENDING    = ".java";   // e.g. ".pde" when CHECK_ONLY_FILES_CONTAINING = true 

boolean SEARCH_RECURSIVE = true;    // search sub-folders
//**************************************************************

//
//states 
final int stateWaitForFolder = 0;  // consts  
final int stateDone          = 1;
final int stateBreak         = 2;  
int state = stateWaitForFolder;  // current

String folderGlobal = "";  

String result = "Searching : "
  +searchPhrase 
  + ":\n"; 

boolean firstTime=true; 

void setup() {
  size (1100, 700); 
  background(111);
  selectFolder("Select a folder to search sub-folders (Cancel to abort). TAKES A LONG TIME TO RUN", 
    "folderSelected");

  if (ALL_UPPER_CASE)
    searchPhrase = searchPhrase.toUpperCase();

  if (searchPhrase.length() < 3)
    println("SHORT SEARCH WORD -- WARNING!");
}

void draw() {
  // 
  switch (state) {

  case stateWaitForFolder:

    // waiting until folder has been selected

    background(111);
    text("Please choose a folder. All sub-folders in the folder will be searched. Hit Cancel to abort.", 
      33, 33);    

    // THE WAIT IS OVER 
    if (!folderGlobal.equals("")) {
      searchFolder( folderGlobal, 0 ); 
      println("");
    } // if 
    break;

  case stateDone:
    background(111);
    text("DONE: " + folderGlobal, 
      33, 33);
    showButtons();
    if (firstTime) {
      println (result+". <<<");
      firstTime=false;
    }
    break;

  case stateBreak:
    background(111);
    text("Window was closed or the user hit cancel.", 33, 33); 
    showButtons(); 
    break; 

  default:
    // error
    println ("error 91"); 
    exit();
    break;
    //
  }  // switch
}  // func 

// -----------------------------------------------------------------------------

void searchFolder(String folderLocal, int depth) {
  // recursive 
  // println (folderLocal);
  String[] strList;

  if (depth==0||depth==1)
    print(".");

  // https://docs.oracle.com/javase/7/docs/api/java/io/File.html 

  File f = dataFile(folderLocal); 
  strList = f.list();
  if (strList!=null) {
    // println ("files in total: " + strList.length);
    int i = 0;
    for (File f1 : f.listFiles()) {
      if (!f1.isFile()) {
        // println ( spaceSigns(depth) + "\"" + f1.getName() +  "\","  );
        if (f1.isDirectory()) {
          // println("call "+depth);
          if (SEARCH_RECURSIVE)
            searchFolder(f1.getAbsolutePath(), depth+1);
        }
      }//if
      else {
        // is a file 
        if ( checkFileName(f1.getName()) ) {
          String[] temp1 = loadStrings(f1.getAbsolutePath());
          String temp2 = join(temp1, " "); 
          if (ALL_UPPER_CASE)
            temp2=temp2.toUpperCase(); 
          if ( temp2.contains(searchPhrase) ) {
            result+= f1.getName() 
              + "\t in "
              + folderLocal 
              + "\n";
          }
        }
      }
    } // for
    // println("");
    state = stateDone; // next state
  }//if
}//func

String spaceSigns(int depth) {
  // makes indents 
  String newS="";
  for (int i=0; i<depth*4; i++)
    newS+=" ";
  return newS;
}//func

boolean checkFileName(String fileName) {
  // depending on CHECK_ONLY_FILES_CONTAINING it returns true or it returns whether the file name contains a file ending ALLOWED_ENDING
  if (CHECK_ONLY_FILES_CONTAINING)
    return fileName.contains(ALLOWED_ENDING); 
  else 
  return true;
}//func 

String getFileName(String fileName) {
  // acts depending on ALL_UPPER_CASE
  if (ALL_UPPER_CASE) 
    return fileName.toUpperCase(); 
  else 
  return fileName;
}// func

// -----------------------------------------------------------------
// file handling 

void folderSelected(File selection) {
  // the 'callback' function.
  if (selection == null) {
    println("Window was closed or the user hit cancel.");
    state=stateBreak;
  } else {
    println("User selected " + selection.getAbsolutePath());
    folderGlobal = selection.getAbsolutePath();
  } // else
}//func 

// ----------------------------------------------------------------
// Input 

void mousePressed() {
  if (state==stateDone||state==stateBreak) {
    if (dist(mouseX, mouseY, 133, 133) < 66) {
      // reset / restart
      folderGlobal=""; 
      selectFolder("Select a folder to rename files (Cancel to abort):", 
        "folderSelected");
      state=stateWaitForFolder;
    }//if
    else if (dist(mouseX, mouseY, 233, 133) < 66) {
      exit();
    }//else if
  }//if
}//func 

//-------------------------------------------------------------------
//Tools

void showButtons() {
  // set mode for text and rect 
  textAlign(CENTER, CENTER);
  rectMode(CENTER);

  // rects 
  noFill();  
  rect(133-5, 133+3, 84, 23);
  rect(233-1, 133+3, 84, 23);

  // text 
  fill(255); 
  text ( "Next folder", 133, 133);
  text ( "Quit", 233, 133);

  // reset 
  textAlign(LEFT);
  rectMode(CORNER); // The default mode is rectMode(CORNER)
}//func 
//
2 Likes
  • 1st step, type in %Temp% or %Tmp% at Windows Explorer’s “Address Bar”.
  • Inside that folder, right-click at anywhere empty and choose “Sort by” -> “Date Modified” & “Descending”.
  • If you had successfully saved your sketch previously, let’s say it’s named “Ball_in_the_Chamber” for example, you’re gonna find subfolders named like this: “Ball_in_the_Chamber5248231791290049437temp”.
  • Either they contain “.class” files only or they contain “.java” files.
  • You need to pick the most recent subfolder containing “.java” files.
  • As @jeremydouglass warned above, you’re gonna need to convert the most recent “.java” files back to the “.pde” syntax.
3 Likes

thanks you so much!!! i finally understood it and successfully converted it from java. How do i avoid this issue in the future?

In menu tools there is archive your Sketch

Use this regularly

Also save your sketch

Make backup

2 Likes

Thank you, thank you so much. You save my all day. Btw, java file could open with Visual Studio, and after small adaptation you can restore all code.

2 Likes