I’m building a UXP plugin in InDesign, and I’m trying to copy a directory and its contents from one place to another. Is the documentation wrong, or am I using fs.copyFile
incorrectly?
The documentation says:
Copies a file or a folder from the source path to the destination path
However, Node’s documentation for fs.copyFile
only mentions using the method for files, and some other sources state it can’t be used for copying folders.
Example code:
const fs = require('fs');
// I would like to copy "Source" and all of its contents into Destination
const srcPath = "/Users/user/Desktop/Source"; // assume this exists
const destPath = "/Users/user/Desktop/Destination"; // assume this exists
const newDestPath = `${destPath}/Source`; // assume this did not exist
fs.mkdir(newDestPath);
fs.copyFile(srcPath, newDestPath);
Manifest snippet:
"requiredPermissions": {
"localFileSystem": "fullAccess",
}
This is the error that fs.copyFile
keeps throwing:
Error: operation not supported on socket
at u (uxp://uxp-internal/webfs_scripts.js:2)
at uxp://uxp-internal/webfs_scripts.js:2
I couldn’t find any helpful advice online, so I’m wondering if the UXP documentation is incorrect.
Do I need to recursively copy each and every file into the destination directory? I would use fs.cp
, but it doesn’t appear to exist in UXP yet.