Access to active document folder nested inside a permanent token saved locaton

As you can see from the sketch below, I insert the original photos in a folder YEAR/DATE/ORIGINALS/, edit the file in Photoshop and export 4 copies in their respective folder, creating the structure seen in the sketch (code created folders structure). The code I wrote works well, but I can only create the folder structure within the YEAR folder (2022), which I saved a permanent token that I call in the code. I would instead like to create the structure into the parent path of the active document I am editing, so that it is then saved in the respective DATE folder. is it possible? i dont want to use getfolder(), because i already have the token for the YEAR folder. I attach the code I have written so far, thank you very much.

const main = async () => {



  //parte di codice che richiama il token salvato per la cartella 

  const app = window.require('photoshop').app

  const batchPlay = require('photoshop').action.batchPlay;

  const fs = require('uxp').storage.localFileSystem;


  //seleziona il token salvato

  token = await JSON.parse(localStorage.getItem("fixfolder"));

  //estrae il percorso della cartella persistente


  const folder = await fs.getEntryForPersistentToken(token);

  //let docDir = path.parse(app.activeDocument.path).dir;



  //acquisisce tutte le cartelle e le crea solo se non sono già state create per il profilo AdobeRGB

  const AdobeRGB = await findOrCreateFolder(folder, "AdobeRGB");

  const sRGB = await findOrCreateFolder(folder, "sRGB");

  const AdobeTIF = await findOrCreateFolder(AdobeRGB, "AdobeTIF");

  const AdobeJPEG = await findOrCreateFolder(AdobeRGB, "AdobeJPEG");

  const sRGBFramed = await findOrCreateFolder(sRGB, "sRGB_Framed");

  const sRGBUnFramed = await findOrCreateFolder(sRGB, "sRGB_Unframed");




  //acquisisce il nome del file e rimuove l'estensione

  const fileName = app.activeDocument.title;

  const fileNameDef = await dothename(fileName);


  //crea il file in modalità modale

  require('photoshop').core.executeAsModal(async () => {

    const newFile = await AdobeRGB.createFile(fileNameDef + ".tif", { overwrite: true });
    const saveFile = await fs.createSessionToken(newFile);





    const result = await batchPlay(
      [
        {
          "_obj": "save",
          "as":
          {
            "_obj": "TIFF",
            "byteOrder":
            {
              "_enum": "platform",
              "_value": "IBMPC"
            },
            "layerCompression":
            {
              "_enum": "encoding",
              "_value": "RLE"
            }
          },
          "in": {
            "_path": saveFile,
            "_kind": "local"
          }
        }
      ], {

      "synchronousExecution": false,
      //"modalBehavior": "fail"
    });

  });


}

//END_MAIN

main();



////////////////////////////////////


//Funzione per scegliere la cartella e salvare il permanent token

//parte di codice che chiede all'utente la cartella fissa e crea il token persistente

const pickfolder = async () => {

  const fs = require('uxp').storage.localFileSystem;

  const fixfolder = await fs.getFolder();   //apre una schermata che permette di scegliere la cartella

  const persistentToken = await fs.createPersistentToken(fixfolder); //crea un token persistente per la cartella

  localStorage.setItem('fixfolder', JSON.stringify(persistentToken));  //associa il token creato alla entry della cartella

}






// funzione che elimina l'estensione dal nome del documento attivo

const dothename = async (fileName) => {

  // Get the position of the last '.' in the file name
  let extensionStart = fileName.lastIndexOf(".");

  // If there is an extension, remove it
  if (extensionStart > -1) {
    fileName = fileName.substring(0, extensionStart);
  }

  // Save the name without extension in a variable
  const nameWithoutExtension = fileName;

  console.log(`File name without extension: ${nameWithoutExtension}`);

  return await nameWithoutExtension;

}


const findOrCreateFolder = async (parentFolder, folderName) => {
  const entries = await parentFolder.getEntries();

  const foundFolder = entries.filter((entry) => entry.isFolder).find((subFolder) => subFolder.name === folderName);

  if (foundFolder) {
    return foundFolder
  }

  return await parentFolder.createFolder(folderName)

}


document.getElementById("button").addEventListener("click", main);

document.getElementById("pickfolderbutton").addEventListener("click", pickfolder);

i solved with this code:

token = await JSON.parse(localStorage.getItem("fixfolder"));

  //estrae il percorso della cartella persistente


  const folder = await fs.getEntryForPersistentToken(token);

  //acquisisce il percorso della cartella parent della cartella parent del documento attivo

let docDir = path.parse(app.activeDocument.path).dir

let parentDir = path.parse(docDir).dir

let parentDir2 = path.parse(parentDir).dir

let parentName = path.parse(parentDir).name



  //acquisisce tutte le cartelle e le crea solo se non sono già state create per il profilo AdobeRGB

  const AdobeRGB = await trovacartella(folder,parentName, "AdobeRGB");

  const sRGB = await trovacartella(folder,parentName, "sRGB");

  const PDS = await trovacartella(folder,parentName,"PSD")

  //crea le sottocartelle delle cartelle principali

  const AdobeTIF = await findOrCreateFolder(AdobeRGB, "AdobeTIF");

  const AdobeJPEG = await findOrCreateFolder(AdobeRGB,"AdobeJPEG");

  const sRGBFramed = await findOrCreateFolder(sRGB,"sRGB_Framed");

  const sRGBUnFramed = await findOrCreateFolder(sRGB,"sRGB_Unframed");


/////////////////////////////////////////////////////////////////////////////////////////////


const trovacartella = async (parentFolder, folderName, folderToCreate) => {
    let foundFolder;
    
    const searchFolder = async (currentFolder) => {
        const entries = await currentFolder.getEntries();
    
        // Cerca la cartella specifica tra le voci della cartella corrente
        foundFolder = entries.filter((entry) => entry.isFolder).find((subFolder) => subFolder.name === folderName);
        if (foundFolder) {
            
          // se la cartella parent del documento attivo viene trovata scrive "trovata"
          console.log("trovata");
            const check = await findOrCreateFolder2(foundFolder, folderToCreate)
            // prima di creare la cartella specificata dal parametro folderToCreate verifica che la cartella esista all'interno della cartella appena cercata
            if (!check) {
            return await foundFolder.createFolder(folderToCreate);
        }
        } else {
            // Se la cartella non è stata trovata, cerca tra le sottocartelle
            for (const entry of entries) {
                if (entry.isFolder) {
                    await searchFolder(entry);
                    if (foundFolder) {
                        return foundFolder;
                    }
                }
            }
        }
    };
    
    foundFolder = await searchFolder(parentFolder);
    if (!foundFolder) {
        return;
    } else {
        return foundFolder;
    }
  };
  
  const findOrCreateFolder2 = async (parentFolder2, folderName2) => {
    const entries = await parentFolder2.getEntries();
  
    const foundFolder2 = entries.filter((entry) => entry.isFolder).find((subFolder) => subFolder.name === folderName2);
  
    if (foundFolder2) {
      return check = true;
    }
  
    return check = false;
  
  };

  const findOrCreateFolder = async (parentFolder2, folderName2) => {
    const entries = await parentFolder2.getEntries();
  
    const foundFolder2 = entries.filter((entry) => entry.isFolder).find((subFolder) => subFolder.name === folderName2);
  
    if (foundFolder2) {
      return check = true;
    }
  
    return check = false;
  
  };

This work, Do you have you better ideas? There isn’t a simple way?