Tools for you: Search file name, Join pde-files and others

Hello all,

today I was searching an old sketch, so I wrote a search sketch I want to share.

It searches a directory and all subfolders recursively:

  • you can alter certain values.

  • It does only check the file name not the content

  • At the moment it searches: Lissajous, non-case-sensitive, recursively, only .pde-files

Chrisir

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

//**************************************************************
// alter these values:
String searchPhrase="Lissajous";  // search this 
boolean ALL_UPPER_CASE = 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 = ".pde";   // 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):", 
    "folderSelected");

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

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 listed. Hit Cancel to abort.", 
      33, 33);    

    // THE WAIT IS OVER 
    if (!folderGlobal.equals("")) {
      searchFolder( folderGlobal, 0 ); 
      //
    } // 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; 

  // 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()) ) {
          if ( getFileName(f1.getName()).contains(searchPhrase)) {
            result+= f1.getName() + " 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 an 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 
//
6 Likes

Another Tool (Meta Tool to work with other Sketches)

here is a sketch that joins pde files and saves as txt file

Useful when you want to post a multiple tab project in the forum.

see Exporting code/copying code/ code management

Chrisir

4 Likes

@Chrisir If you want sophisticated code management you could do a lot worse than use atom. I use it all the time with my ruby-processing projects. You can easily set it up to run scripts for you as I have with my JRubyArt plugin.

3 Likes

Another Tool (Meta Tool)

it generates for-loops, when you need several nested for loops:



void setup() {

  size(800, 600);

  int numberOfDesiredForLoops = 9; 

  for (int i = 0; i < numberOfDesiredForLoops; i++) {
    println ( " for (int i"+i+" = 0; i"+i+" < 2; i"+i+"++) { " );
  }

  println ("");
  for (int i = 0; i < numberOfDesiredForLoops; i++) {
    print ( "i"+i+",");
  }
  println ("");
  println ("");

  for (int i = 0; i < numberOfDesiredForLoops; i++) {
    println ( "} // for ");
  }
  println ("");

  exit();
} // func 
//
4 Likes

Another Tool (Metatool)

it converts lists of data without “” to with “”

// This tool (meta tool) takes csv data from a text file named "text.txt"
// and converts it into a code segment defining the content of the text file 
// as a String array in your code.
//
// Copy the String array from the Direct Window of this processing Sketch into your sketch. 
//
// Example usage: You have a Level Editor for a game. The level editor just gives out data like 
// 0,0.0,0.0,0.0,400.0,2.0,400.0,-16570625 in its direct window.
// 
// Save the data (ctrl-a, ctrl-c) and put it into a text file (ctrl-v). 
// Use this tool to convert the text file.
// Paste the result into the Game to show the new level you made in the level editor. 

// See example data below.

// (easier when you improve your export tool or when you use loadStrings in your target sketch)

size(155, 155); 

String[] list=loadStrings("text.txt");

println("String[] list=\n{"); 

for (String s1 : list) {
  println("\""
    +s1
    +"\","
    );
}//for 

println("};");


/*

 Start Content of text.txt
 
 //Export (id, pos vector in 3D, size vector in 3D, color)------------------------------
 0,0.0,0.0,0.0,400.0,2.0,400.0,-16570625
 1,-400.0,0.0,0.0,400.0,10.0,400.0,-65536
 2,-400.0,0.0,-400.0,400.0,10.0,400.0,-1
 3,0.0,0.0,-400.0,400.0,10.0,400.0,-16570625
 
 etc.
 
 RESULT: -------------------------------------- 
 
 String[] list=
 {
 "0,0.0,0.0,0.0,400.0,2.0,400.0,-16570625",
 "1,-400.0,0.0,0.0,400.0,10.0,400.0,-65536",
 "2,-400.0,0.0,-400.0,400.0,10.0,400.0,-1",
 "4,0.0,0.0,-400.0,400.0,10.0,400.0,-16570625"
 };
 
 
 */
2 Likes

Haha, this man is truly a coder. This is truly something you begin to notice.

3 Likes

similar to the search tool above, but this new tool does a full text search INSIDE the pde files (and does not search the file name except for .pde)

// very slow !! Checks full text content of each pde file !!! (and not really the file name)
// function fileHasSearchText() is important here
// 
// user selects folder, all sub-folders are searched

//**************************************************************
// alter these values:
String searchPhrase= "Join3DArray"; // "CHECK_ONLY_FILES_CONTAINING";  // "Lissajous";  // search this 
// this should be false!!!!! Because the full text of the file is NOT turned UPPER CASE 
boolean ALL_UPPER_CASE = false; // not case-sensitive OR case-sensitive
// This says: We only check files with ending .pde 
boolean CHECK_ONLY_FILES_CONTAINING = true; // we can search for a certain file type only e.g. ".pde"
String ALLOWED_ENDING = ".pde";   // e.g. ".pde" when CHECK_ONLY_FILES_CONTAINING is true 
boolean SEARCH_RECURSIVE = true;    // search sub-folders
//**************************************************************

// following values not for users to change (only for programmers / if you know what you are doing)
//states 
final int stateWaitForFolder = 0;  // consts  
final int stateDone          = 1;
final int stateBreak         = 2;  
int state = stateWaitForFolder;  // current

String folderGlobal = "";  

// This String is filled with the search results 
String result = "Searching full text: "
  + searchPhrase 
  + ":\n"; 

boolean firstTime=true; 

void setup() {
  size (1100, 700); 
  background(111);
  selectFolder("Select a folder to search sub-folders (Cancel to abort):", 
    "folderSelected");

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

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

  case stateWaitForFolder:
    // waiting until folder has been selected
    background(111);
    text("Please choose a folder. Depending on the flags all sub-folders in the folder will be searched (full text search). Hit Cancel to abort.", 
      33, 33);    

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

  case stateDone:
    background(111);
    text("DONE: " 
      + folderGlobal
      + ". See direct window for results. ", 
      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 

// -----------------------------------------------------------------------------
// Further core functions 

void searchFolder(String folderLocal, int depth) {
  // recursive function going over folder content
  // println (folderLocal);
  String[] strList; 

  // 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);  // recursive
        }//if
      }//if
      else {
        // It is a file 
        if ( checkFileName(f1.getName()) ) {
          // old version for check of the file name
          //  if ( getFileName(f1.getName()).contains(searchPhrase)) {
          // }
          // NEW version for check of the file full text content 
          if (fileHasSearchText(f1.getPath())) {
            result+= f1.getName() + " in " + folderLocal + "\n";
          }
        }
      }//else
    } // for
    // println("");
    state = stateDone; // next state
  }//if
}//func

boolean fileHasSearchText(String name_) {
  // Is the seatch text in the full text?  
  // println (name_); 
  String[] text1 = loadStrings(name_);
  String text2 = join (text1, "#"); 

  return
    text2.contains ( searchPhrase );
}

String spaceSignsOLD(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 an file ending ALLOWED_ENDING

  // if criteria CHECK_ONLY_FILES_CONTAINING is true 
  if (CHECK_ONLY_FILES_CONTAINING) {
    // we check and return result
    return fileName.contains(ALLOWED_ENDING);
  } else { 
    // else we return true always 
    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() {
  // check Buttons
  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 ( "Choose folder", 133, 133);
  text ( "Quit", 233, 133);

  // reset 
  textAlign(LEFT);
  rectMode(CORNER); // The default mode is rectMode(CORNER)
}//func 
//
3 Likes

Did you ever had to write 9 nested for-loops?

for (int i0 = 0; i0 < 2; i0++) { 
    for (int i1 = 0; i1 < 2; i1++) { 
      for (int i2 = 0; i2 < 2; i2++) { 
         ....
            ......

I wrote another Sketch to write these 9 lines with for-loops for me, so I don’t have to do it.

You can copy paste the auto-generated code from the direct window in processing:


void setup() {

  size(800, 600);

  int numberOfDesiredForLoops = 9; 

  for (int i = 0; i < numberOfDesiredForLoops; i++) {
    println ( " for (int i"+i+" = 0; i"+i+" < 2; i"+i+"++) { " );
  }

  println ("");
  for (int i = 0; i < numberOfDesiredForLoops; i++) {
    print ( "i"+i+",");
  }
  println ("");
  println ("");

  for (int i = 0; i < numberOfDesiredForLoops; i++) {
    println ( "}");
  }
  println ("");

  exit();
} // func 
//
2 Likes

Similarly, I was needing a list of 3D-PVectors that point in all 3D-directions.

I received help from the forum here.

 PVector[] pvList = 
    {  
    // new PVector ( 0,  0,  0),   // This can be removed
    new PVector ( 0, 0, 1), // forward
    new PVector ( 0, 0, -1), // reverse
    new PVector ( 0, 1, 0), 
    new PVector ( 0, 1, 1), 
    new PVector ( 0, 1, -1), 
     .....
     ......

So I wrote a Sketch to generate the list.

You have to copy the result list from the direct window of the processing IDE and then replace 2 with -1 by the processing Find-function, ctrl-f:

size(300, 300); 

println("PVector[] pvList1 = "); 
println("    {"  );

for (int i0 = 0; i0 < 3; i0++) { 
  for (int i1 = 0; i1 < 3; i1++) { 
    for (int i2 = 0; i2 < 3; i2++) { 
      println(
        "        new PVector ( "  
        + str(i0)+", "
        +str(i1)+", "
        +str(i2)
        +" ),");
    }//for
  }
}

println("};");

The List

Here is the result:


PVector[] pvList = 
    {  
    // new PVector ( 0,  0,  0),   // This can be removed
    new PVector ( 0, 0, 1), // forward
    new PVector ( 0, 0, -1), // reverse
    new PVector ( 0, 1, 0), 
    new PVector ( 0, 1, 1), 
    new PVector ( 0, 1, -1), 
    new PVector ( 0, -1, 0), 
    new PVector ( 0, -1, 1), 
    new PVector ( 0, -1, -1), 

    new PVector ( 1, 0, 0), 
    new PVector ( 1, 0, 1), 
    new PVector ( 1, 0, -1), 
    new PVector ( 1, 1, 0), 
    new PVector ( 1, 1, 1), 
    new PVector ( 1, 1, -1), 
    new PVector ( 1, -1, 0), 
    new PVector ( 1, -1, 1), 
    new PVector ( 1, -1, -1), 

    new PVector ( -1, 0, 0), 
    new PVector ( -1, 0, 1), 
    new PVector ( -1, 0, -1), 
    new PVector ( -1, 1, 0), 
    new PVector ( -1, 1, 1), 
    new PVector ( -1, 1, -1), 
    new PVector ( -1, -1, 0), 
    new PVector ( -1, -1, 1), 
    new PVector ( -1, -1, -1), 
  };

3D-graphic

And a 3D-graphic to demonstrate the use of the list.

The lines pointing outwards from the center are the PVectors:


float angle1; 

// auto-generated list of 3D PVectors for all possible directions in 3D (right, left, up, diagonal right downwards....)
PVector[] pvList1 = 
  {
  //  new PVector ( 0, 0, 0 ), 
  new PVector ( 0, 0, 1 ), 
  new PVector ( 0, 0, -1 ), 
  new PVector ( 0, 1, 0 ), 
  new PVector ( 0, 1, 1 ), 
  new PVector ( 0, 1, -1 ), 
  new PVector ( 0, -1, 0 ), 
  new PVector ( 0, -1, 1 ), 
  new PVector ( 0, -1, -1 ), 
  new PVector ( 1, 0, 0 ), 
  new PVector ( 1, 0, 1 ), 
  new PVector ( 1, 0, -1 ), 
  new PVector ( 1, 1, 0 ), 
  new PVector ( 1, 1, 1 ), 
  new PVector ( 1, 1, -1 ), 
  new PVector ( 1, -1, 0 ), 
  new PVector ( 1, -1, 1 ), 
  new PVector ( 1, -1, -1 ), 
  new PVector ( -1, 0, 0 ), 
  new PVector ( -1, 0, 1 ), 
  new PVector ( -1, 0, -1 ), 
  new PVector ( -1, 1, 0 ), 
  new PVector ( -1, 1, 1 ), 
  new PVector ( -1, 1, -1 ), 
  new PVector ( -1, -1, 0 ), 
  new PVector ( -1, -1, 1 ), 
  new PVector ( -1, -1, -1 ) 
};

void setup() {
  // init
  size(800, 600, P3D);
} // func 

void draw() {
  // runs on and on 
  background(0);
  lights();

  stroke(255, 0, 0);
  strokeWeight(8);

  pushMatrix();
  translate(width/2, height/2, 0);
  rotateX(-0.2992);
  rotateY(angle1); 

  int i=0; 
  for (PVector pv : pvList1) {
    float amt = map(i, 
      0, pvList1.length, 
      0, 1);
    stroke(lerpColor(color(255), color(255, 0, 0), amt));
    line(
      //0, 0, 0, 
      pv.x*8, pv.y*8, pv.z*8, 
      pv.x*88, pv.y*88, pv.z*88);
    i++;
  }//for
  popMatrix();
  //

  stroke(100); 
  //  noFill();
  fill(255, 0, 0);

  pushMatrix();
  translate(100, 100, 0);
  rotateZ(angle1);
  if (!keyPressed)
    angle1+=.04; 
  box(60);
  popMatrix();

  pushMatrix();
  translate(400, 100, 0); 
  rotateX(angle1);
  fill(0, 0, 255);
  box(60);
  popMatrix();

  pushMatrix();
  translate(700, 100, 0);
  rotateY(angle1);
  box(60);
  popMatrix();

  pushMatrix();
  translate(700, 300, -330);
  noStroke(); 
  sphere(50);
  popMatrix();
} // func 
//
3 Likes

I made another Tool or Meta Tool

Here you can grab (using the mouse) a color from an existing image and get the color code

Chrisir

PImage sourceImage; 
color colorGlobal  =  color(209.0, 139.0, 70.0); 
String colorText = ""; 

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

void setup() {
  size(1470, 770);

  sourceImage=loadImage("chess.jpg");  // whatever 
}

void draw() {
  background(111); 

  // show image 
  image(sourceImage, 0, 0);

  // show control rect 
  fill(colorGlobal);
  stroke(0); 
  rect(sourceImage.width+0, 110, 
    60, 60);

  // show help
  fill(0); 
  text("This Sketch lets you receive a color from a given image.\nClick with the mouse a color in the image.\n"
    +colorText, 
    sourceImage.width+40, 210);
}

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

void mousePressed() {
  color coloFromMouse = 
    sourceImage.get(mouseX, mouseY);

  colorText = " = color( " 
    + int(red(coloFromMouse))
    +", "
    +int(green(coloFromMouse))
    +", "+
    int(blue(coloFromMouse))
    +" );"; 
  println(colorText);
  colorGlobal = color( red(coloFromMouse), green(coloFromMouse), blue(coloFromMouse) );
}
//

2 Likes

If you need to write 9 nested for-loops you’ve got bigger problems than simply typing them out!:sweat_smile:

2 Likes

When you use the Sketch above to join all pde files of a Sketch to one text-file (to post it on the forum easily):

  • This new Sketch does the opposite. It makes a new folder on the HD, distributes the text file (the joined Sketch) and makes for each section a new pde file (a tab) and pasts the content.

Chrisir


// distribute / SPREAD Textfile content Into multiple Pde-Files.
// The Anti-Sketch to the Sketch JoinSketch which joins all pde files to 1 text file.
// This Sketch reverses this process.
//
//
//states
final int stateWaitForFolder = 0;  // consts
final int stateDone          = 1;
final int stateBreak         = 2;
int state = stateWaitForFolder;  // current

String folderGlobal = "";

final String delim1 = "// ********************************************************************************";

int linesInTotal=0;

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

void setup() {
  size (1100, 700);
  background(111);
  selectInput("Select a file to make pdes (Cancel to abort).",
    "fileSelected");
}

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

  case stateWaitForFolder:
    // waiting until folder has been selected
    background(111);
    text("Please choose a folder. Hit Cancel to abort.",
      33, 33);

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

  case stateDone:
    background(111);
    text("DONE: " + folderGlobal,
      33, 33);
    showButtons();
    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 distributeTextfileIntoPdeFiles(String fileLocal) {
  //
  // println (folderLocal);
  // https://docs.oracle.com/javase/7/docs/api/java/io/File.html

  String[] strList;
  String result = "";
  String nameCurrentPdeFile="";
  final String extension=".pde";

  // load text file
  strList = loadStrings(fileLocal);
  println("Loaded: " + strList.length);

  // Make a new folder
  String folderName = "";
  folderName = retrieveFolderName(strList);
  if (folderName.equals("")) {
    // Error
    println("Failed to get folder name. Can't make a new folder.");
    exit();
    return;
  }
  File f1=new File(sketchPath("")+"//"+folderName);
  if (f1.mkdir()) {
    // success
  } else {
    // Error
    println("Failed to make folder"
      +folderName
      +". Probably delete the existing folder of the same name first. ");
    exit();
    return;
  }

  println("");

  // Parse text file
  for (String s1 : strList) {

    String nameCurrentPdeFileBuffer=retrieveNameCurrentPdeFile(s1, extension);
    if (!nameCurrentPdeFileBuffer.equals(""))
      nameCurrentPdeFile=nameCurrentPdeFileBuffer;

    if (s1.equals(delim1) && !nameCurrentPdeFile.equals("")) {
      // save
      if (result.trim().length()>0) {
        // save
        String fileName =
          sketchPath("")
          +"//"+folderName
          +"//"+nameCurrentPdeFile
          +extension;
        result=result.replace("\n\n\n\n", "\n");
        result=result.replace("\n\n\n", "\n\n");
        saveStrings(fileName,
          split(result, "\n") );
        // reset
        result="";
        nameCurrentPdeFile="";
      }
    } else {
      // add new line to current file content
      result += s1+ "\n";
    }
  }//for
  //
  state = stateDone; // next state
}//func

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

String retrieveFolderName(String[] strListLocal) {

  String name1="";
  final String extension=".pde";

  for (String s1 : strListLocal) {

    if (s1.startsWith("// tab: ")) {
      // hit
      String s2=s1;
      s2=trim(s2);
      s2 = s2.replace("// tab: ", "");
      name1=s2;
      name1=trim(name1);
      int i1 = name1.indexOf(extension);
      name1=name1.substring(0, i1);
      println("Folder name for the new Sketch: "+name1);
      s2 = s2.replace(extension, "");
      return name1;
    }
  }
  // Failed
  return "";
}

String retrieveNameCurrentPdeFile(String s1, String extension) {

  String nameCurrentPdeFile="";

  if (s1.startsWith("// tab: ")) {
    // hit
    String s2=s1;
    s2=trim(s2);
    s2 = s2.replace("// tab: ", "");
    nameCurrentPdeFile=s2;
    nameCurrentPdeFile=trim(nameCurrentPdeFile);
    int i1 = nameCurrentPdeFile.indexOf(extension);
    nameCurrentPdeFile=nameCurrentPdeFile.substring(0, i1);
    println("Name for next pde file "+nameCurrentPdeFile+"<");
    return nameCurrentPdeFile;
  }
  // Failed
  return "";
}

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

void fileSelected(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="";
      linesInTotal=0;
      selectFolder("Select a folder to rename files (Cancel to abort):",
        "folderSelected");
      state=stateWaitForFolder;
    } else if (dist(mouseX, mouseY, 233, 133) < 66) {
      // Quit
      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", 133, 133);
  text ( "Quit", 233, 133);

  // reset
  textAlign(LEFT);
  rectMode(CORNER); // The default mode is rectMode(CORNER)
}//func
//

keywords: Tool or Meta Tool or MetaTool or Meta-Tool or Sketch-Tool or Forum Tool Some Tools I made

2 Likes

To join all pde files in a single txt, in windows you could use old good msdos console:

find /v "Supercalifragilisticexpialidocious" *.pde > outfile.text

Assuming you didn’t use the text “Supercalifragilisticexpialidocious” inside any of your sketches, you will get the following text inside outfile:

main.pde ------
(Content of main.pde)
----------
secondfile.pde ------
(Content of secondfile.pde)
----------
1 Like