Copy link to clipboard
Copied
Hi guys,
i have an array populated with media that i would like to copy in another folders on hard drive. Is possible throught scripting to copy files on disk?
Thank you
Yes, if your CEP panel has Node.js enabled, you can copy files with fs.copyFile() or fs.copyFileSync()
var fs = require('fs');
// Sync Method
fs.copyFileSync(sourcePath, destinationPath);
// Async Method
fs.copyFile(sourcePath, destinationPath, function(err){
if (err) throw err;
console.log('File Copied');});
If you're looking for an ExtendScript solution, you can use file.copy() on a file object.
var myFile = new File(pathToFile);
myFile.copy(pathToNewFile);
Node.js is typically faster if you can us
...Copy link to clipboard
Copied
Yes, if your CEP panel has Node.js enabled, you can copy files with fs.copyFile() or fs.copyFileSync()
var fs = require('fs');
// Sync Method
fs.copyFileSync(sourcePath, destinationPath);
// Async Method
fs.copyFile(sourcePath, destinationPath, function(err){
if (err) throw err;
console.log('File Copied');});
If you're looking for an ExtendScript solution, you can use file.copy() on a file object.
var myFile = new File(pathToFile);
myFile.copy(pathToNewFile);
Node.js is typically faster if you can use that method.
Copy link to clipboard
Copied
I tryied to use the second solution, but the file.copy() return false and doesn't copy anything.
Here is my code:
var importFolder = new Folder;
importFolder = Folder.selectDialog("open a folder");
for(var t=0;t<video.length; t++)
{
var myFile = new File(video
.projectItem.getMediaPath()); var response = myFile.copy(importFolder);
}
(in myFile i checked that there is a valid path)
Thank you
Copy link to clipboard
Copied
The argument for file.copy() is a path, not a folder object. So you'll need to get the path from your selected folder first like this:
var importFolder = new Folder;
importFolder = Folder.selectDialog("open a folder");
importFolder = importFolder.fsName;
Copy link to clipboard
Copied
Mhh, it doesn't work.
I used .fsName and now i have the right path of the target folder, but it doesn't copy the files.
I also tried (for test only) using direct file path like "f:\work\video.mp4" but it still not working.
Thank you..
Here is the code:
var importFolder = new Folder;
importFolder = Folder.selectDialog("Open a folder");
importFolder = importFolder.fsName;
var myFile = new File("f:\work\video.mp4");
myFile.copy(importFolder);
Copy link to clipboard
Copied
Firstly, you need to use double backslashes in PC paths to represent a single backslash, otherwise Javascript/Extendscript thinks you're trying to escape characters.
Secondly, you need the full path to the file, not the folder.
var importFolder = new Folder;
importFolder = Folder.selectDialog("Open a folder");
var myFile = new File("F:\\work\\video.mp4");
var newFileName = importFolder.fsName + '\\' + 'copied_' + myFile.name; // creates the full path to the new file
myFile.copy(newFileName);
Copy link to clipboard
Copied
Awesome! A huge thanks Justin, you helped me a lot
Copy link to clipboard
Copied
Glad it worked, happy to help!
Copy link to clipboard
Copied
Hi
as you have imagined, i'm not a coder, but i have a basic knowledge, so now i'm a bit confused. I read the links you have posted in my other discussion and looked for others, but it's too much complicated for my actual skills.
Reading, i found this information, but i don't know if it's correct:
I have to add in the "manifest.xml", in the <resource> tag the following lines:
<CEFCommandLine>
<Parameter>--enable-nodejs</Parameter>
</CEFCommandLine>
and then use the code of your first answer...Is it correct or is a bit more complicated?
Thank you