# Saving Multiple Files in the same folder

**URL:** <https://forums.creativeclouddeveloper.com/t/saving-multiple-files-in-the-same-folder/3780>\
**Category:** Photoshop\
**Created:** [October 22, 2021, 1:47pm UTC](https://forums.creativeclouddeveloper.com/t/saving-multiple-files-in-the-same-folder/3780 "2021-10-22T13:47:56Z")\
**Posts on this page:** 3\
**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:** [October 22, 2021, 1:47pm UTC](https://forums.creativeclouddeveloper.com/t/saving-multiple-files-in-the-same-folder/3780/1 "2021-10-22T13:47:56Z")

</div>

For some reason I still can’t wrap my head around the save/token system in UXP

I’ve got a function that saves 2 different files in a folder. At the moment I’m only able to get the function to run if it chooses the folder to save the file every time.

Is there a way to select the save folder on the first file, and then keep it as the save folder for the next one so the user is not alerted/cant change it?

It runs over 30+ files so for the user to click save 30 times is tedious

Current Function Below

```auto
document.querySelector("Btn01").onclick = () => {
    makeWebFiles();
}

async function makeWebFiles() {

    const batchPlay = require("photoshop").action.batchPlay;
    const fs = require("uxp").storage.localFileSystem;
    const pluginFolder = await fs.getPluginFolder();
    const doc1 = await pluginFolder.getEntry("doc1.tif");
    const doc2 = await pluginFolder.getEntry("doc2.tif");

    await app.open(doc1);
    await saveWeb("doc1.jpg");
    await app.open(doc2);
    await saveWeb("doc2.jpg");

    async function saveWeb(saveFileName) {

        const persistentFolder = await fs.getFolder();
        const newFile = await persistentFolder.createFile(saveFileName, { overwrite: true });
        const saveFile = await fs.createSessionToken(newFile);

        const result = await batchPlay(
            [
                {
                    "_obj": "save",
                    "as": {
                        "_obj": "JPEG",
                        "extendedQuality": 8,
                        "matteColor": {
                            "_enum": "matteColor",
                            "_value": "none"
                        }
                    },
                    "in": {
                        "_path": saveFile,
                        "_kind": "local"
                    },
                    "copy": true,
                    "lowerCase": true,
                    "saveStage": {
                        "_enum": "saveStageType",
                        "_value": "saveBegin"
                    },
                },
                {
                    "_obj": "close",
                    "saving": {
                        "_enum": "yesNo",
                        "_value": "no"
                    },
                }
            ], {
            "synchronousExecution": false,
            "modalBehavior": "fail"
        });
    }
}

```

---

<div class="post-metadata">

**Author:** ![ddbell](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/ddbell/32/1030_2.png) [@ddbell](https://forums.creativeclouddeveloper.com/u/ddbell)\
**Post date:** [October 22, 2021, 9:39pm UTC](https://forums.creativeclouddeveloper.com/t/saving-multiple-files-in-the-same-folder/3780/2 "2021-10-22T21:39:35Z")

</div>

Without testing it… it should be something like this

```auto
const batchPlay = require("photoshop").action.batchPlay;
    const fs = require("uxp").storage.localFileSystem;
    const pluginFolder = await fs.getPluginFolder();
    const doc1 = await pluginFolder.getEntry("doc1.tif");
    const doc2 = await pluginFolder.getEntry("doc2.tif");
    const persistentFolder = await fs.getFolder();

//Probably best to create a loop to assign the file, create the token and save for each file

    await app.open(doc1);
    let newFile = await persistentFolder.createFile("doc1.jpg", { overwrite: true });
    let saveFile = await fs.createSessionToken(newFile);
    await saveWeb(saveFile);
   //may want to add a doc close step

    await app.open(doc2);
    newFile = await persistentFolder.createFile("doc2.jpg", { overwrite: true });
    saveFile = await fs.createSessionToken(newFile);
    await saveWeb(saveFile);
   //may want to add a doc close step

async function saveWeb(saveFile) {

        const result = await batchPlay(
            [
                {
                    "_obj": "save",
                    "as": {
                        "_obj": "JPEG",
                        "extendedQuality": 8,
                        "matteColor": {
                            "_enum": "matteColor",
                            "_value": "none"
                        }
                    },
                    "in": {
                        "_path": saveFile,
                        "_kind": "local"
                    },
                    "copy": true,
                    "lowerCase": true,
                    "saveStage": {
                        "_enum": "saveStageType",
                        "_value": "saveBegin"
                    },
                },
                {
                    "_obj": "close",
                    "saving": {
                        "_enum": "yesNo",
                        "_value": "no"
                    },
                }
            ], {
            "synchronousExecution": false,
            "modalBehavior": "fail"
        });
    }
}

```

---

<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:** [October 22, 2021, 10:53pm UTC](https://forums.creativeclouddeveloper.com/t/saving-multiple-files-in-the-same-folder/3780/3 "2021-10-22T22:53:46Z")

</div>

Fantastic, that works - thank you so much. It’s so much easier to understand once there is a relevant code example
