getEntryWithUrl

I’m finding that getEntryWithUrl isn’t working as it used to.
This code used to work and now it’s returning the following error.

const lfs = require("uxp").storage.localFileSystem;
const doc = app.activeDocument;
const path = doc.path.slice(0, doc.path.lastIndexOf("\\"));
const entry = await lfs.getEntryWithUrl(`file:/${path}`);

Screenshot 2023-06-30 015030

I’ve got "fullAccess" set in my manifest and I’m running PS 24.6.0/UXP 7.1.0 and using the vanilla UDT starter plugin with no other code.
Obviously the folder exists being that path is pulled directly from the active doc. That triple slash in the error looks weird to me, so I tried it getEntryWithUrl with both

(`file:${path}`)

and

(`${path}`)

but the error is the same regardless.

Is this just me having a senior moment and missing something dumb or has something changed?

@sttk3 - I know you’ve cracked this in the past, any ideas?

1 Like

Now I will point out a few things I noticed.


Treating paths as just strings is a bad practice because it depends on the specific environment; use Path module. Path modules are defined as ‘path’ in UXP and should not be overwritten with a variable of the same name.

const path = doc.path.slice(0, doc.path.lastIndexOf("\\"));

getEntryWithUrl no longer needs a prefix ‘file:’.

const entry = await lfs.getEntryWithUrl(`file:/${path}`);

Here is the fixed code.

const lfs = require('uxp').storage.localFileSystem ;
const { app } = require('photoshop') ;

const main = async () => {
  const doc = app.activeDocument ;
  const folderPath = path.dirname(doc.path) ;
  const entry = await lfs.getEntryWithUrl(folderPath) ;
  console.log(entry) ;
  // --> n {Symbol(_name): "files", Symbol(_provider): {…}, Symbol(_id): {…}}
} ;
1 Like

@sttk3 nice one mate! I’d missed the introduction of the path module.

1 Like

@sttk3 actually, that still returns the same error. I’ve tried different files in various locations on the filesystem and always the same :frowning:
Is there something else I’ve missed?

const lfs = require("uxp").storage.localFileSystem;
const doc = app.activeDocument;
const folderPath = path.dirname(doc.path);

console.log("raw path", doc.path);
console.log("path", folderPath);

const entry = await lfs.getEntryWithUrl(folderPath);

console.log(entry);

My manifest:

{
  ...,
  "requiredPermissions": {
    "localFileSystem": "fullAccess"
  }
}

@Timothy_Bennett It should work, but I notice my environment is still Photoshop 24.5.0. I will update it and try it.

1 Like

@Timothy_Bennett It worked in my environment. Does it not work because you are on Windows? It would be helpful to have another person’s verification.

  • macOS 11.7.6 (Apple Silicon)
  • Photoshop 2023 (24.6.0)

Is it possible that it should be file:// instead of file:/// ? I don’t understand why I see it in the screenshot of the error in console.

That looked odd to me too - that’s nothing to do with me, it feels like getEntryWithUrl is adding an extra /.
I’ve tried it with:

getEntryWithUrl(folderPath)
getEntryWithUrl(`file:${folderPath}`)
getEntryWithUrl(`file:/${folderPath}`)

and they all return the same error/url.

What do you pass in? Backslash or forwardslash? In folderPath

You can see in my screenshot above that folderPath returns backslashes.

I tried the code below on Windows10 and it completely works.

but after I deleted requiredPermissions on manifest.json I found same error.
I think you could have problem on manifest.json.
could you update full of manifest code?

1 Like

:person_facepalming: I still had the manifest version set to 4, rookie, rookie mistake

2 Likes