Copy link to clipboard
Copied
For example: Copy all files under
‘..preSetting’ + ‘/bb/’
to
Folder.desktop + ‘/aa/’
My path structure is as follows, with “Script” at the same level as preSetting:
D:/OO/Script/myscript.jsx
D:/OO/preSetting/bb/
This one below seems wrong.
//var activeDocPath = String(app.activeDocument.fullName);
var copyToPath = String(Folder.desktop + '/aa/');
var sPath = String("/" + PreSetting + '/bb/');
//alert(sourcePath);
//alert(pShortcut);
var copiedFile = copyFile(sPath, copyToPath);
function copyFile(sourcePath, destinationPath) {
var fp = Folder(sourcePath)
//get the files in MyFiles
var f = fp.getFiles();
alert(f);
alert(f.length);
for (var i = 0; i < f.length; i++) {
//try {
if (!f[i].exists) {
throw new Error('File not found: "' + sourcePath + '".');
}
else {
var dup = File(destinationPath);
f[i].copy(dup)
return dup;
}
}
}
Try this:
//Folders named Source and Dest on the desktop
copyFile(Folder.desktop + "/Source", Folder.desktop + "/Dest");
function copyFile(sourcePath, destinationPath) {
var fs = Folder(sourcePath).getFiles();
for (var i = 0; i < fs.length; i++) {
fs[i].copy(destinationPath + "/" + fs[i].name);
}
}
Copy link to clipboard
Copied
Hi @dublove ,
look into DOM documentation for object File and method copy(). There you'll see that the argument in copy() is not just a folder path, but a string describing a file's path ( or a File object ). So in essence you have to add the file name to the target's folder path and do:
copy( destinationPath +"/"+ f[i].name )
What also should work is:
copy( File( destinationPath +"/"+ f[i].name ) )
https://www.indesignjs.de/extendscriptAPI/indesign-latest/#File.html#d1e6347__d1e6984
Regards,
Uwe Laubender
( Adobe Community Expert )
PS: Edited post.
Copy link to clipboard
Copied
How do I represent the relative path to bb?
My source file's relationship to the current script:
D:/OO/Script/myscript.jsx
D:/OO/pre/bb/
Is that how it works?
var myScript = app.activeScript;
alert(myScript.parent.parent);
Copy link to clipboard
Copied
This would get the path to the script’s folder:
https://www.indesignjs.de/extendscriptAPI/indesign-latest/#$.html
var sf = File($.fileName).parent
alert("This script’s parent folder: \r\r" + sf)
//returns /Applications/Adobe%20InDesign%202024/Scripts/Scripts%20Panel
Copy link to clipboard
Copied
Thank you very much.
The path issue has been resolved.
My script is located here: app.activeScript.parent.parent
The code below cannot copy directories.
If there is a folder, the line 'fs[i].copy(dup);' will report that there is no such function named 'copy()".
copyFile(sPath, copyToPath);
function copyFile(sourcePath, destinationPath) {
var fd = Folder(sourcePath)
var fs = fd.getFiles();
for (var i = 0; i < fs.length; i++) {
var dup = File(destinationPath + "/" + fs[i].name);
alert(dup);
fs[i].copy(dup);
}
}
Copy link to clipboard
Copied
Try this:
//Folders named Source and Dest on the desktop
copyFile(Folder.desktop + "/Source", Folder.desktop + "/Dest");
function copyFile(sourcePath, destinationPath) {
var fs = Folder(sourcePath).getFiles();
for (var i = 0; i < fs.length; i++) {
fs[i].copy(destinationPath + "/" + fs[i].name);
}
}
Copy link to clipboard
Copied
The same issue occurs: the folder attachment is not copied, the process is interrupted, and an error pops up.
Without the folder, everything works fine.
Copy link to clipboard
Copied
Show the code you are running that throws the error
Copy link to clipboard
Copied
Hi rob day.
I'm using this exact script you provided.
This script does not support deleting folders.
Copy link to clipboard
Copied
This script does not support deleting folders.
The script I provided isn’t deleting any files, it’s copying the files. If you are trying to delete files show us the code that is throwing the error.
Copy link to clipboard
Copied
HI @rob day
Only deleted the file; everything is working fine.
That's enough. I'm giving up on deleting the folder.
Thank you very much,.
Copy link to clipboard
Copied
@dublove said: "… That's enough. I'm giving up on deleting the folder."
First the folder has to be all empty before you will be able to delete it. All empty also means no subfolders or files are there; even invisible files should not be there.
Regards,
Uwe Laubender
( Adobe Community Expert )
Copy link to clipboard
Copied
Hi @dublove ,
when the error is "copy is not a function" it might be that fs[i] is not a file.
Also check if the extra slash "/" is already part of destinationPath.
Regards,
Uwe Laubender
( Adobe Community Expert )
Find more inspiration, events, and resources on the new Adobe Community
Explore Now