Save File with user defined Native path

I’m trying to figure out how to how to save a file in a given folder, without the folder dialogue popping up each time.

Currently I have a button that lets the user select a folder, and stores it path as a value.

C:\Users\UserName\Desktop\

async function getFolderPath(){
    const persistentFolder = await fs.getFolder();
    setFilePath(persistentFolder.nativePath)
}

I’m using a function to save a file like below

async function saveFile() {

    const folder = await fs.getFolder();
    const newFile = await folder.createFile("testFile.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,
    });  
 }

Is there a way to set the folder path from that value without bringing up the folder select dialogue each time. Basically bypass the folder selection like it would if you saved it to the data folder with fs.getDataFolder()?

Thanks

I had a hard time with that as well…this is what I ended up doing but I am guessing there is probably a more elegant way. (I fumble my way through all of this) :wink:

I did like you did in your getFolderPath function, but then I saved that to localStorage so it will always stay set.

var myFolder = await require("uxp").storage.localFileSystem.getFolder();
        let token = await require("uxp").storage.localFileSystem.createPersistentToken(myFolder);
        localStorage.setItem("persistent-token", token);

Then when it comes time to make the file, I pull that like this:

const entry = await require("uxp").storage.localFileSystem.getEntryForPersistentToken(localStorage.getItem("persistent-token"));
const newFile = await entry.createFile("\test.tif", { overwrite: true });
const saveFile = await require("uxp").storage.localFileSystem.createSessionToken(newFile);

@JasonM, plaease use three backticks ``` instead of //--- to paste the code. Will be much easier to read for everyone :wink:

Oh cool…I wasn’t aware. Edited.

Yeah sweet as, that works no problem. Didn’t realise you can set then get the token - thank you.