Script for XYPlorer to automatically create (next available) JD folder

I have caught myself “cheating” on the system.
When in a rush, I sometimes deviate from the JD system.

To enforce dicipline, I asked AI to create a script for XYPlorer to check folders in current folder, and then increment by one - prompting what to name the new folder.

Here’s the script, if useful to anyone:

:: // Step 1: Get all folders in current directory (non-recursive)
  $folders = folderreport("dirs", "r", <curpath>, , , 0);

  // Step 2: Initialize max Johnny.Decimal number
  $maxJD = 0;

  // Step 3: Loop through folder names to find highest JD number
  foreach($f, $folders, <crlf>) {
      $folderName = gpc($f, "file");
      $prefix = substr($folderName, 0, 5);
      if (regexmatches($prefix, "^\d{2}\.\d{2}$")) {
          $num = replace($prefix, ".", ""); // e.g., 00.01 → 0001
          if ($num > $maxJD) {
              $maxJD = $num;
          }
      }
  }

  // Step 4: Increment the number
  $nextNum = $maxJD + 1;

  // Step 5: Pad to 4 digits manually using substr (simulate right())
  $nextNumStr = "0000" . $nextNum;
  $nextNumStr = substr($nextNumStr, -4); // take last 4 chars, e.g., "0002"

  // Step 6: Convert to Johnny.Decimal format: NN.NN
  $nextJD = substr($nextNumStr, 0, 2) . "." . substr($nextNumStr, 2, 2); // e.g., "00.02"

  // Step 7: Ask for folder description
  $desc = input("Enter description for new folder:", "New Description");
  if ($desc == "") { end "Cancelled."; }

  // Step 8: Build full folder name and create it
  $folderName = "$nextJD $desc";
  $fullPath = "<curpath>\$folderName";
  run "cmd /c mkdir ""$fullPath""";
2 Likes

Hi @fender (I’ve got one of your guitars hanging on the wall, btw) :guitar:

I’m not familiar with XYplorer, but I get the gist of the code. I can see that it creates a new folder, calculating the next number. I guess you have one folder per category and run the script in the context of the Category folder?

What I’m wondering is how it works with the JDex - have you got another script that compiles your Index?

  • Initially, I was making entries into the JDex diligently (hard rule, no exceptions).

  • When creating a new Area or ID, I’d update the JDex.

  • Currently, I navigate more by Area and ID (in other words, looking for the right folder and go from there) - than I do by the navigating in the JDex.

  • Yes, I’ve let the JDex slip “out of sync” (as a semi-conscientious choice) - befitting my natural workflow.

  • I might regret it - but updating the JDex (based on a dump of the folder structures) isn’t too large of a task, so I have a way to get back on track, if needed.

Cool. It’s always interesting to see how other people use the system!