I am trying to access the directory of the current active document, search that directory for images which share the first 9 digits of the active documents name, then open those matching files.
Is this possible?
I am searching on the local filesystem not in the pre-made plugin folders.
The below code works up until it reaches the try/catch
This is my code:
const fsProvider = require('uxp').storage.localFileSystem;
const app = require('photoshop').app
const activeDocumentPath = app.activeDocument.path;
const result = activeDocumentPath.replace(/\/[^/]*$/, "");
// Find Retouch Notes Folder Function
async function findFolder(path) {
// Access other location
if (fsProvider.isFileSystemProvider) {
try {
const pluginFolder = await fsProvider.getEntryWithUrl(path);
const folderArray = await pluginFolder.getEntries();
const name = app.activeDocument.name.split("").slice(0,9).join("")
for(const obj of folderArray){
if(name == obj.name.split("").slice(0,9).join("")){
console.log(`${obj.name} is a match!`);
console.log(`${path}/${obj.name}`)
// Now I have the files path, how do I open a file in photoshop?
try{
const fd = await app.open(`${path}/${obj.name}`);
} catch (error){
console.log(error)
}
}
};
} catch (e) {
console.error(e);
}
}
}
findFolder(result)
This is the error that’s returned:
Error: Parameter must be a valid entry representing a file or a folder\
at Object._getEntryDataToNative (uxp://uxp-internal/webfs_scripts.js:2)\
at Object.createSessionToken (uxp://uxp-internal/webfs_scripts.js:2)\
at Object.createSessionToken (uxp://uxp-internal/webfs_scripts.js:2)\
at Object.createSessionToken (uxp://uxp-internal/webfs_scripts.js:2)\
at Photoshop.open (uxp://uxp-internal/ps-app.js:1)\
at findFolder (VM12 main.js:45)