# Get file name from session tokken

**URL:** <https://forums.creativeclouddeveloper.com/t/get-file-name-from-session-tokken/6206>\
**Category:** UXP Plugin API\
**Tags:** uxp, javascript\
**Created:** [April 21, 2023, 12:42am UTC](https://forums.creativeclouddeveloper.com/t/get-file-name-from-session-tokken/6206 "2023-04-21T00:42:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hsehtak](https://avatars.discourse-cdn.com/v4/letter/h/a6a055/32.png) [@hsehtak](https://forums.creativeclouddeveloper.com/u/hsehtak)\
**Post date:** [April 21, 2023, 12:42am UTC](https://forums.creativeclouddeveloper.com/t/get-file-name-from-session-tokken/6206/1 "2023-04-21T00:42:35Z")

</div>

HI Everyone  
I m trying to make a UXP for photoshop in which at the beginning i am taking taking images from user. i instantly converted them to tokens and saved in an array, now at the later stages of my plugin i want to loop through those images and get the name of all images.  
The problem is that now the array contain the session tokens , hwo i should get the name without opening each image.

> Blockquote  
> const fileTypes = [“jpg”, “jpeg”, “png”];  
> const options = {  
> types: fileTypes,  
> canSelectMultiple: true  
> };  
> const pickedFiles = await fs.getFileForOpening(options);  
> if (pickedFiles) {  
> pickedFiles.forEach(pImg =\> {  
> srcPathTokken.push(fs.createSessionToken(pickedFiles))  
> });  
> }

> Blockquote

// and in addition to that can any expert guide me how to handle the flow next time for a structure like that

Thanks

---

<div class="post-metadata">

**Author:** ![Timothy\_Bennett](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/timothy_bennett/32/1251_2.png) [@Timothy\_Bennett](https://forums.creativeclouddeveloper.com/u/Timothy_Bennett)\
**Post date:** [April 21, 2023, 7:23am UTC](https://forums.creativeclouddeveloper.com/t/get-file-name-from-session-tokken/6206/2 "2023-04-21T07:23:07Z")

</div>

When you push to the array why not push an object that includes the filename and the token as properties?

---

<div class="post-metadata">

**Author:** ![Maher](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/maher/32/1432_2.png) [@Maher](https://forums.creativeclouddeveloper.com/u/Maher)\
**Post date:** [April 21, 2023, 7:55am UTC](https://forums.creativeclouddeveloper.com/t/get-file-name-from-session-tokken/6206/3 "2023-04-21T07:55:01Z")

</div>

a token is a string and not an object, so as it is you can’t get anything from it.  
your options are:

1. convert it back to entry when needed and get name from entry _(not recommended)_

```auto
myEntry = await fs.getEntryForPersistentToken(myToken)
fileName = myEntry.name

```

* * *

1. get and store file path and/or name from entry while converting it to a token

I’d store my tokens as an array of objects

```auto
let fileTypes = ["jpg", "jpeg", "png"];
let options = {
    types: fileTypes,
    allowMultiple: true //not canSelectMultiple
      };
let myFiles = await fs.getFileForOpening(options);

if (myFiles){
    let myTokens = myFiles.map((myEntry) => {
        return {
        name: myEntry.name,
        path: myEntry.nativePath,
        token: fs.createSessionToken(myEntry)
        }
    })
}

```

now the array called `myTokens` will contain a list of objects

```auto
[{
      name: "file1.jpg",
      path: "D:\myFolder\file1.jpg",
      token: "session-token/xxxxxxxxxxx"
},
{
      name: "file2.jpg",
      path: "D:\myFolder\file2.jpg",
      token: "session-token/xxxxxxxxxxx"
}]

```

to loop through it:

```auto
myTokens.forEach(myToken => {
      console.log(myToken.name);
      console.log(myToken.path);
      console.log(myToken.token);
})

```

you can also store just the path of the file and get name like this:

```auto
let fileName = path.basename(myToken.path)

```

---

<div class="post-metadata">

**Author:** ![hsehtak](https://avatars.discourse-cdn.com/v4/letter/h/a6a055/32.png) [@hsehtak](https://forums.creativeclouddeveloper.com/u/hsehtak)\
**Post date:** [April 23, 2023, 2:59am UTC](https://forums.creativeclouddeveloper.com/t/get-file-name-from-session-tokken/6206/4 "2023-04-23T02:59:21Z")

</div>

because i am too weak in programming, 😅  
got the solution now. Thankyou
