can i open all files in a folder using persistent token? I created a persistent token for a folder, can I now ask to open all files in that same folder?
const fs = require('uxp').storage.localFileSystem;
let entry = await fs.getFolder();
let token = fs.createPersistentToken(entry);
localStorage.setItem("persistentFolder", token);
const thePersistentFolderToken = localStorage.getItem("persistentFolder");
const thePersistentFolder = await fs.getEntryForPersistentToken(thePersistentFolderToken);
// show all files
let files = await thePersistentFolder.getEntries();
let filesArray = [];
for (let i = 0; i < files.length; i++) {
filesArray.push(files[i].name);
}
app.open = filesArray;
You just need to open each file individually within your loop rather than pushing to an array and passing that to app.open().
You’ll need to use .getEntry() and pass the returned value to app.open(). You’ll also need to use executeAsModal to perform the file open.
See here for more detail.
Sorry, I was being dumb, you don’t need to use getEntry() because you already did with getEntries()
You have multiple await calls but they’re not wrapped in an async function and so won’t work. You want something more like this (I changed the for loop to a nicer for…of loop and changed the let declarations to const):