# UXP accessing files and folders

**URL:** <https://forums.creativeclouddeveloper.com/t/uxp-accessing-files-and-folders/5930>\
**Category:** UXP Plugin API\
**Tags:** uxp, javascript, api-feedback\
**Created:** [February 26, 2023, 12:06pm UTC](https://forums.creativeclouddeveloper.com/t/uxp-accessing-files-and-folders/5930 "2023-02-26T12:06:52Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![Adobe256](https://avatars.discourse-cdn.com/v4/letter/a/3e96dc/32.png) [@Adobe256](https://forums.creativeclouddeveloper.com/u/Adobe256)\
**Post date:** [February 26, 2023, 12:06pm UTC](https://forums.creativeclouddeveloper.com/t/uxp-accessing-files-and-folders/5930/1 "2023-02-26T12:06:52Z")

</div>

I would love to get some clarification on the FS module. According to the documentation a native “file:” scheme for the path parameter can be used to access and read the file. I’m in a situation where I want to read a file using the FS.readFile path but instead I keet on getting the `error "Route not found"`. what could be the issue or the way out. below is my code

```auto
let path = "file:///C:/Users/chelse/united /Pictures/Screenshots/cup.jpg"
const data = await FS.readFile(path);

```

Again how do you check for the existence of a file in a folder since FS.existSync doesn’t exist on uxp.

---

<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:** [February 26, 2023, 12:41pm UTC](https://forums.creativeclouddeveloper.com/t/uxp-accessing-files-and-folders/5930/2 "2023-02-26T12:41:04Z")

</div>

`require('uxp').storage.localFileSystem` does not allow reading or writing files without user interaction.  
namely: `fs.getFolder()`, `fs.getFileForOpening()` and `fs.getFileForSaving("hello.txt")`

read more about getting access to the local file system [here](https://developer.adobe.com/xd/uxp/develop/reference/uxp/storage-index/#getting-access-to-the-local-file-system)

to check the existence of a file, you request acces to it by using `getFileForOpening` or by using [folder.getEntry(filePath)](https://developer.adobe.com/xd/uxp/develop/reference/uxp/module/storage/#foldergetentryfilepath--promisefilefolder)

then you check if is defined / if [entry.isFile](https://developer.adobe.com/xd/uxp/develop/reference/uxp/module/storage/#entryisfile--boolean)

you may also want to create a “token” from entry.  
a token is a string that can be used in batchPlay and can be persistent or temporary

* * *

also check out [require(‘fs’)](https://developer.adobe.com/photoshop/uxp/2022/uxp/reference-js/Modules/FileSystem/)

---

<div class="post-metadata">

**Author:** ![Adobe256](https://avatars.discourse-cdn.com/v4/letter/a/3e96dc/32.png) [@Adobe256](https://forums.creativeclouddeveloper.com/u/Adobe256)\
**Post date:** [February 26, 2023, 12:43pm UTC](https://forums.creativeclouddeveloper.com/t/uxp-accessing-files-and-folders/5930/3 "2023-02-26T12:43:13Z")

</div>

what is the difference between the above fs and this [https://developer.adobe.com/xd/uxp/uxp/reference-js/Modules/FileSystem/](https://developer.adobe.com/xd/uxp/uxp/reference-js/Modules/FileSystem/)

I thought I could access the file using the fs.readFile listed in the above

---

<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:** [February 26, 2023, 12:49pm UTC](https://forums.creativeclouddeveloper.com/t/uxp-accessing-files-and-folders/5930/4 "2023-02-26T12:49:30Z")

</div>

[require(‘fs’)](https://developer.adobe.com/photoshop/uxp/2022/uxp/reference-js/Modules/FileSystem/) can’t be used for saving and opening files (in the context of PS documents and images) AFAIK. it just reads raw data and does not return an entry file so it can’t be used with functions that expects entries.  
it also requires permissions in the manifest.

however I read in the forums that arbitrary file access is planned but I wouldn’t hold my breath

---

<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:** [February 26, 2023, 1:31pm UTC](https://forums.creativeclouddeveloper.com/t/uxp-accessing-files-and-folders/5930/5 "2023-02-26T13:31:54Z")

</div>

See my thread here for a working example of using `fs.readdir()`.  
Worth noting that you also need to grant `fullAccess` permission for local in your manifest.

> [@getEntryWithUrl not accepting valid path](http://forums.creativeclouddeveloper.com/t/getentrywithurl-not-accepting-valid-path/5927):
>
> I’m trying out the new getEntryWithUrl() method and I’m not having much luck. I’ve included fs.readdir() to test the path is working. readdir returns the folder contents fine, but getEntryWithUrl throws its toys out of the pram with the same path. I also included the example from the documentation for accessing the plugin data folder and it returns the same error. Anyone got this to work yet that can provide some pointers? Or alternatively, is getEntryWithUrl pre-release? PS: 24.2.0 API: 2 …

---

<div class="post-metadata">

**Author:** ![Adobe256](https://avatars.discourse-cdn.com/v4/letter/a/3e96dc/32.png) [@Adobe256](https://forums.creativeclouddeveloper.com/u/Adobe256)\
**Post date:** [February 26, 2023, 2:28pm UTC](https://forums.creativeclouddeveloper.com/t/uxp-accessing-files-and-folders/5930/6 "2023-02-26T14:28:43Z")

</div>

how do you grant fullAccess permission for local in manifest. I can’t see that in the documentation

---

<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:** [February 26, 2023, 5:45pm UTC](https://forums.creativeclouddeveloper.com/t/uxp-accessing-files-and-folders/5930/7 "2023-02-26T17:45:07Z")

</div>

It’s [here](https://developer.adobe.com/photoshop/uxp/2022/guides/uxp_guide/uxp-misc/manifest-v5/#local-filesystem) on the documentation page for Manifest V5.

---

<div class="post-metadata">

**Author:** ![sttk3](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@sttk3](https://forums.creativeclouddeveloper.com/u/sttk3)\
**Post date:** [February 26, 2023, 9:56pm UTC](https://forums.creativeclouddeveloper.com/t/uxp-accessing-files-and-folders/5930/8 "2023-02-26T21:56:18Z")

</div>

There may be too many ‘/’ after ‘file:’. Would the following example work?

```auto
const FS = require('fs');
let path = "file:C:\\Users\\chelse\\united \\Pictures\\Screenshots\\cup.jpg";
const data = await FS.readFile(path);

```

In this example, I have changed the path to a Windows-style path. The only reason is that I am not familiar with how the drive letter (C:) is represented in a POSIX path. In macOS it should look something like this.

```auto
const FS = require('fs');
let path = "file:/Users/chelse/united /Pictures/Screenshots/cup.jpg";
const data = await FS.readFile(path);

```

---

<div class="post-metadata">

**Author:** ![Adobe256](https://avatars.discourse-cdn.com/v4/letter/a/3e96dc/32.png) [@Adobe256](https://forums.creativeclouddeveloper.com/u/Adobe256)\
**Post date:** [February 26, 2023, 10:40pm UTC](https://forums.creativeclouddeveloper.com/t/uxp-accessing-files-and-folders/5930/9 "2023-02-26T22:40:35Z")

</div>

Then this solution would be tricky for me since am working on manifest 4

---

<div class="post-metadata">

**Author:** ![Adobe256](https://avatars.discourse-cdn.com/v4/letter/a/3e96dc/32.png) [@Adobe256](https://forums.creativeclouddeveloper.com/u/Adobe256)\
**Post date:** [February 26, 2023, 10:42pm UTC](https://forums.creativeclouddeveloper.com/t/uxp-accessing-files-and-folders/5930/10 "2023-02-26T22:42:26Z")

</div>

I’ve tried the windows version and it keeps on throwing,` "Route not found"`. None of the above solution works for me. Funny thing is, I’ve copy pasted the link from windows file system itself where it works correctly and pasted it in the editor and tried running it and thus the error. I’ve copy pasted the link as you pasted and pasted it on windows and windows threw an error.

---

<div class="post-metadata">

**Author:** ![sttk3](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@sttk3](https://forums.creativeclouddeveloper.com/u/sttk3)\
**Post date:** [February 26, 2023, 10:56pm UTC](https://forums.creativeclouddeveloper.com/t/uxp-accessing-files-and-folders/5930/11 "2023-02-26T22:56:40Z")

</div>

My solution also assumes that you are using manifest v5 and giving fullAccess permission for local. Sorry.

---

<div class="post-metadata">

**Author:** ![Adobe256](https://avatars.discourse-cdn.com/v4/letter/a/3e96dc/32.png) [@Adobe256](https://forums.creativeclouddeveloper.com/u/Adobe256)\
**Post date:** [February 26, 2023, 11:19pm UTC](https://forums.creativeclouddeveloper.com/t/uxp-accessing-files-and-folders/5930/12 "2023-02-26T23:19:14Z")

</div>

Nope. Am on manifest 4. is it of a neccessity that all plugins relying on manifest 4 shift to manifest 5  
?

---

<div class="post-metadata">

**Author:** ![Adobe256](https://avatars.discourse-cdn.com/v4/letter/a/3e96dc/32.png) [@Adobe256](https://forums.creativeclouddeveloper.com/u/Adobe256)\
**Post date:** [February 27, 2023, 1:19am UTC](https://forums.creativeclouddeveloper.com/t/uxp-accessing-files-and-folders/5930/13 "2023-02-27T01:19:03Z")

</div>

Thanks guys. with manifest 5 it has worked

---

<div class="post-metadata">

**Author:** ![MalbertCunha](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/malbertcunha/32/2760_2.png) [@MalbertCunha](https://forums.creativeclouddeveloper.com/u/MalbertCunha)\
**Post date:** [February 27, 2023, 1:34am UTC](https://forums.creativeclouddeveloper.com/t/uxp-accessing-files-and-folders/5930/14 "2023-02-27T01:34:33Z")

</div>

It didn’t work here! @Adobe256 would you mind showing how the file code turned out. js and the changes I have to make to the manifest file? Thanks

---

<div class="post-metadata">

**Author:** ![Adobe256](https://avatars.discourse-cdn.com/v4/letter/a/3e96dc/32.png) [@Adobe256](https://forums.creativeclouddeveloper.com/u/Adobe256)\
**Post date:** [February 27, 2023, 1:54am UTC](https://forums.creativeclouddeveloper.com/t/uxp-accessing-files-and-folders/5930/15 "2023-02-27T01:54:57Z")

</div>

First of all update your UXP to the latest version. Also make sure Photoshop is beyond version 23.0.0 + . Maneuver to this link [[https://developer.adobe.com/photoshop/uxp/2022/guides/uxp\_guide/uxp-misc/manifest-v5/#local-filesystem](https://developer.adobe.com/photoshop/uxp/2022/guides/uxp_guide/uxp-misc/manifest-v5/#local-filesystem)]([https://localfilesystem](https://localfilesystem) permission) and enable the FullAccess permission on your manifest. the above code works well. Make sure the manifest version reads 5+. Actually, try create a sample plugin using the uxp create plugin button and experiment. I’ll share the code in a few when am completely done

---

<div class="post-metadata">

**Author:** ![Adobe256](https://avatars.discourse-cdn.com/v4/letter/a/3e96dc/32.png) [@Adobe256](https://forums.creativeclouddeveloper.com/u/Adobe256)\
**Post date:** [March 8, 2023, 8:59am UTC](https://forums.creativeclouddeveloper.com/t/uxp-accessing-files-and-folders/5930/17 "2023-03-08T08:59:23Z")

</div>

Oh sorry I had forgotten. .

on your manifest 5 add this after icons.

```auto
 "requiredPermissions": {
        "localFileSystem": "fullAccess", // this is important for the access
      // with regards to the question the rest is not of much importance
        "network": {
            "domains": [
                "http://forums.creativeclouddeveloper.com/t/uxp-accessing-files-and-folders/5930/15",                        
            ]
        }, 
    "launchProcess": {
        "schemes": [
          "http",
          "https"
        ],
        "extensions": [
          ".svg",
          ".png",
          ".pdf",
          ".xd", 
          ".psd"
        ]
      },
       "allowCodeGenerationFromStrings": true        
    }

```

// code for reading file from disk

```auto

 function readFileFromDisk() {
  try {
    // make sure an active doc is opened
    // check if any file is open. if not return error
    let activeDocument = (PS.app.activeDocument as PS.Document) || null
    if (activeDocument === null) {
      return psCore.showAlert({ message: 'Please open a document' })
    }   

    // check if file is saved before proceeding
    if(!activeDocument.save){
      // request the user to save it 
//return an alert
}

    // fetching the file
 
    if (activeDococument.path === undefined) {
    // for some reasons am yet to understand the path is undefined for some files
      return psCore.showAlert('Error fetching file path.')
    }
    
    // read the file
    const fileBuffer: ArrayBuffer = await FS.readFile(`file:${activeDoc.path}`) // 

    // fetch the file's name
    let fileName: string = activeDocument.title

  console.log('filename', fileName,' file Array Buffer ', fileBuffer) 

    
  } catch (error) {
    console.error(' Error : ', error)
   
  }
}

```

---

<div class="post-metadata">

**Author:** ![Zob](https://avatars.discourse-cdn.com/v4/letter/z/87869e/32.png) [@Zob](https://forums.creativeclouddeveloper.com/u/Zob)\
**Post date:** [January 30, 2024, 6:15pm UTC](https://forums.creativeclouddeveloper.com/t/uxp-accessing-files-and-folders/5930/18 "2024-01-30T18:15:28Z")

</div>

I kept getting this error as well, my problem was I did not have “file:” as a prefix on the fullpath string.

good:  
`"file:c:\\path\\to\\allowed\\file.json"`  
bad:  
`"c:\\path\\to\\allowed\\file.json"`

---

<div class="post-metadata">

**Author:** ![morph3us](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/morph3us/32/3099_2.png) [@morph3us](https://forums.creativeclouddeveloper.com/u/morph3us)\
**Post date:** [February 8, 2024, 12:17pm UTC](https://forums.creativeclouddeveloper.com/t/uxp-accessing-files-and-folders/5930/19 "2024-02-08T12:17:28Z")

</div>

Thats all I got to contribute and it is the total opposite of Zobs opinion:

> [@Session Token for Folder?](http://forums.creativeclouddeveloper.com/t/session-token-for-folder/7407/3):
>
> Thats embarrasing… I saw that post, but didnt get its meaning at first… Thanks for pointing me in the right direction! There is some cross correlation, though, as this was not the only problem. I found [this](http://forums.creativeclouddeveloper.com/t/cant-access-certain-network-drive-when-using-localfilesystem-getentrywithurl/6619) thread, which lead me to believe that something is wrong with using a network drive, as a counter test revealed that getting a session token of a local folder was fine. Basically now I am not referencing \\Server\[...], but rather beginning from the assigned network letter S:\[...]. And …

I am not a professional, but for me it worked.
