Entry.moveTo
successfully *copies a folder and its contents, but does not respond with a success or error afterward. In fact, the async function will continue to run, preventing any code that follows from running unless I remove the await
call before it. It’s possible this is a local permissions issue, however, I would then expect a permissions error as a response. The same is true for Entry.copyTo
.
Removing await
is not a solution since the moved data is necessary for further operations. I’ve also tried removing await
, and setting a long timeout function afterward, but that didn’t seem to help.
// const distEntryName = 'the name of some folder inside the React dist directory'
const filesystem = require("uxp").storage.localFileSystem;
let dataFolder = await filesystem.getDataFolder();
let distFolder = await filesystem.getPluginFolder();
let distEntry = await distFolder.getEntry(distEntryName);
console.log("begin") // prints
let response = await distEntry.moveTo(
dataFolder,
{overwrite: true}
);
console.log(response) // does not print
console.log("end") // does not print
What does filesystem.getPluginFolder("src")
do? Does getPluginFolder()
accept any arguments? What’s the returned entryObject
?
The TLDR is that I’m moving distributed plugin data from a read-only location to somewhere where I can read/write.
Both are native functions to the UXP API. Here’s a further breakdown:
filesystem.getPluginFolder()
This folder “…contains the plugin related packaged assets.” The react starter, generates a /dist
directory when a plugin is built. Any files or folders placed into this directory are available after distributing a plugin, but are read-only. As far as the options go, that seems to be a mistake on my part - it doesn’t seem to take any but functions whether or not I give it one. I’ve edited the code above to be a little clearer, sorry for the trouble.
filesystem.getDataFolder()
This folder “…can be used for extension’s data storage without user interaction. It is persistent across host-app version upgrades.” So it’s plugin specific data available to developers without user input being necessary. Locally, it’s available on my machine at C:\Users\[username]\AppData\Roaming\Adobe\UXP\PluginsStorage\PHSP\[ps version]\Developer\ab_react\PluginData,
and the same is true for any users of the plugin (on windows).
moveTo
does not make sense when starting from the pluginFolder
– the plugin’s folder is immutable, and files cannot be removed from it by the plugin. You should be getting an error message on this attempt (so if it’s moving the data, that’s a bug).
copyTo
should work (fyi @sujai, @pkrishna , sounds like it’s not), but if it isn’t, you can use read
and write
to copy the contents of the file to the target location.
Side note: getPluginFolder
does not take any parameters. getPluginFolder("src")
is going to return the same folder entity as getPluginFolder()
.
2 Likes
You’re right, moveTo
is not currently moving, it’s copying - probably because of the immutability you’re highlighting. But just to confirm copyTo
is not working. Read/write seems like a good work-around for the time being (with some recursion since it’s a folder with plenty of internal files/folders).
oh! You’re trying to move a folder…?
There’s one other property you need to add –
const response = await distEntry.moveTo(dataFolder,
{overwrite: true, allowFolderCopy: true});
See if that gets you any further.
Ok, so if I first delete my previously copied folder, then re-run - all the print statements will work and the code will continue to run beyond the copy statement (so it’s working correctly).
However, the overwriting option does not seem to be working. Because if I edit the contents of the original folder, then re-run, I get the previous issue (no response, code that follows does not run).
So basically, this will work for distribution purposes, but not within my development environment.
Maybe it’s also worth mentioning, some of the files being moved are Extend Script JSX that will be fired via batch play.