# Save File with user defined Native path

**URL:** <https://forums.creativeclouddeveloper.com/t/save-file-with-user-defined-native-path/4162>\
**Category:** Photoshop\
**Created:** [January 18, 2022, 1:56am UTC](https://forums.creativeclouddeveloper.com/t/save-file-with-user-defined-native-path/4162 "2022-01-18T01:56:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![matakus](https://avatars.discourse-cdn.com/v4/letter/m/49beb7/32.png) [@matakus](https://forums.creativeclouddeveloper.com/u/matakus)\
**Post date:** [January 18, 2022, 1:56am UTC](https://forums.creativeclouddeveloper.com/t/save-file-with-user-defined-native-path/4162/1 "2022-01-18T01:56:09Z")

</div>

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\

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

```

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

```auto
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

---

<div class="post-metadata">

**Author:** ![JasonM](https://avatars.discourse-cdn.com/v4/letter/j/3be4f8/32.png) [@JasonM](https://forums.creativeclouddeveloper.com/u/JasonM)\
**Post date:** [January 18, 2022, 3:15am UTC](https://forums.creativeclouddeveloper.com/t/save-file-with-user-defined-native-path/4162/2 "2022-01-18T03:15:13Z")

</div>

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) 😉

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

```auto
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:

```auto
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);

```

---

<div class="post-metadata">

**Author:** ![Karmalakas](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/karmalakas/32/1048_2.png) [@Karmalakas](https://forums.creativeclouddeveloper.com/u/Karmalakas)\
**Post date:** [January 18, 2022, 7:32am UTC](https://forums.creativeclouddeveloper.com/t/save-file-with-user-defined-native-path/4162/3 "2022-01-18T07:32:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![JasonM](https://avatars.discourse-cdn.com/v4/letter/j/3be4f8/32.png) [@JasonM](https://forums.creativeclouddeveloper.com/u/JasonM)\
**Post date:** [January 18, 2022, 8:11am UTC](https://forums.creativeclouddeveloper.com/t/save-file-with-user-defined-native-path/4162/4 "2022-01-18T08:11:14Z")

</div>

Oh cool…I wasn’t aware. Edited.

---

<div class="post-metadata">

**Author:** ![matakus](https://avatars.discourse-cdn.com/v4/letter/m/49beb7/32.png) [@matakus](https://forums.creativeclouddeveloper.com/u/matakus)\
**Post date:** [January 18, 2022, 11:59am UTC](https://forums.creativeclouddeveloper.com/t/save-file-with-user-defined-native-path/4162/5 "2022-01-18T11:59:24Z")

</div>

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