# Batch open single file

**URL:** <https://forums.creativeclouddeveloper.com/t/batch-open-single-file/9122>\
**Category:** Photoshop\
**Created:** [January 25, 2025, 11:33am UTC](https://forums.creativeclouddeveloper.com/t/batch-open-single-file/9122 "2025-01-25T11:33:10Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![haller](https://avatars.discourse-cdn.com/v4/letter/h/53a042/32.png) [@haller](https://forums.creativeclouddeveloper.com/u/haller)\
**Post date:** [January 25, 2025, 11:33am UTC](https://forums.creativeclouddeveloper.com/t/batch-open-single-file/9122/1 "2025-01-25T11:33:10Z")

</div>

I’m creating a small panel to perform batch resizing  
this small code allows me to open all the files contained in a folder  
but I would like to open them one at a time

the flow should be like this:  
opens a photo, resizes it, closes the image and opens the other photo,

I have already created the script to resize and save  
I only need the function to open one file at a time

this is what I have now

```auto
const {app,core: { executeAsModal }} = require("photoshop");
const {storage: { localFileSystem: lfs }} = require('uxp');
const fs = require("uxp").storage.localFileSystem;
input_folder_to_use = await lfs.getEntryWithUrl(my folder) 

all_images_to_use = await input_folder_to_use.getEntries(input_folder_to_use);

for (const current_image of all_images_to_use) {

    const openDocumentToken = await fs.createSessionToken(current_image);
    const open_specified_image_file = {
        _obj: "open",
        null: {
            _path: openDocumentToken,
            _kind: "local"
        }

    };

    await app.batchPlay([open_specified_image_file]);

```

---

<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 25, 2025, 12:09pm UTC](https://forums.creativeclouddeveloper.com/t/batch-open-single-file/9122/2 "2025-01-25T12:09:20Z")

</div>

What happens next in your loop? Is this cut of the pasted script intentional? You can skip the resize and save. Do you close the file after that? Based on what is visible, it seems it should work on files one by one

---

<div class="post-metadata">

**Author:** ![haller](https://avatars.discourse-cdn.com/v4/letter/h/53a042/32.png) [@haller](https://forums.creativeclouddeveloper.com/u/haller)\
**Post date:** [January 25, 2025, 1:49pm UTC](https://forums.creativeclouddeveloper.com/t/batch-open-single-file/9122/3 "2025-01-25T13:49:07Z")

</div>

Karmalaka The above script loads me all the photos that are in the folder I indicated in lgetEntryWithUrl.  
He doesn’t upload them to me one at a time but all at once.  
The resizing script is not included.  
So I need a script that, once the folder has been indicated, opens one file at a time and not all at once as happens now.  
I hope I explained myself well.

---

<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 25, 2025, 2:56pm UTC](https://forums.creativeclouddeveloper.com/t/batch-open-single-file/9122/4 "2025-01-25T14:56:53Z")

</div>

I’m a bit confused

> [@haller](#):
>
> The above script loads me all the photos that are in the folder I indicated in lgetEntryWithUrl.  
> He doesn’t upload them to me one at a time but all at once.

Do you mean, that even without the `for` loop it opens the files as soon as you execute this?

```js
input_folder_to_use = await lfs.getEntryWithUrl(my folder) 
all_images_to_use = await input_folder_to_use.getEntries(input_folder_to_use);

```

* * *

Also you didn’t show what you’re doing at the end of your `for` loop. It’s cut off in the middle in your example

---

<div class="post-metadata">

**Author:** ![haller](https://avatars.discourse-cdn.com/v4/letter/h/53a042/32.png) [@haller](https://forums.creativeclouddeveloper.com/u/haller)\
**Post date:** [January 26, 2025, 8:16am UTC](https://forums.creativeclouddeveloper.com/t/batch-open-single-file/9122/5 "2025-01-26T08:16:29Z")

</div>

Yes, that’s right once the folder is indicated it opens all the files contained in it. These strings below are the continuation, Where I specify where to save the file.

let myDir = await lfs.getEntryWithUrl(“My folder”); //Mac  
let myFile = await myDir.createFile(“pollo.jpg”, { overwrite: true });  
await app.activeDocument.saveAs.jpg(myFile, { quality: 12 }, true);

The scaling part is missing which I have yet to see how to fit it into the process.
