Copy link to clipboard
Copied
Suppose my script directory is:
..\myFile\myScript\copyToGrep.jsx
My regular expression directory is:
..\myFile\myGrep\aaa.xml
I want to copy aaa.xml to the GREP directory:
C:\Users\olo\AppData\Roaming\Adobe\InDesign\Version 19.0-J\zh_CN\Find-Change Queries\GREP
First clear the files in GREP, then copy. The version number 19.0 is automatically recognized.
Alternatively, if can open the specified directory in the script, which is also a good option.
Hi @dublove, here is a generic function to copy a file from `sourcePath` to `destinationPath`.
- Mark
/**
* @file Copy File Example.js
*
* Example copying the active document file
* to the desktop named "copy.indd".
*
* @author m1b
* @version 2025-08-20
*/
(function () {
if (0 === app.documents.length)
return alert('Please open a document and try again.');
var activeDocPath = String(app.activeDocument.fullName);
var copyToPath = Folder.desktop + '/copy.indd';
...
Hi @dublove ,
what do you get with:
alert(app.scriptPreferences.scriptsFolder.parent.parent.parent.name);
or the whole path with:
alert(app.scriptPreferences.scriptsFolder.parent.parent.parent.fsName);
Regards,
Uwe Laubender
( Adobe Community Expert )
I want to copy all files to a specific path, such as aa, but nothing happens.
var copyToPath = Folder.desktop + ‘/aa/’;
Hi @dublove , It needs to be — Folder(Folder.desktop + "/aa");
To check if the folder exist:
var copyToPath = Folder(Folder.desktop + "/aa");
alert("Does a folder at " + copyToPath + " exist?\r" + copyToPath.exists)
To create a folder:
var copyToPath = new Folder(Folder.desktop + "/aa");
copyToPath.create();
To delete the folder:
copyToPath.remove();
Also there are
How to delete files in a folder.
$.writeln(Folder.userData)
//returns ~/Library/Application Support on OSX
$.writeln(Folder.userData.parent)
//parent is ~/Library
//creates a new folder named HellowWorld in my Find-Change Queries/GREP folder
var hw = new Folder(Folder.userData.parent + "/Preferences/Adobe InDesign/Version 16.0/en_US/Find-Change Queries/GREP/HellowWorld")
hw.create();
//Gets the folder named MyFiles on my Desktop
var dtf = Folder(Folder.desktop + "/MyFiles")
//Permanently
@dublove asked: "Is there one for all documents?"
There is no single command to delete all files in one folder or directory.
Nothing like files.everyItem().remove(). You have to use getFiles() first* and then loop the files you found to remove them one by one. And of course that can fail if there are restrictions in the user's rights to manage files.
* And you have to sort them out, getFiles() will also find folders.
Also, as far as I know, you will not be able to delete a folder or direct
...You can try a getFiles loop as @Laubender suggests—this works for me. Just be aware that remove() deletes the file—it will not be recoverable from the trash:
//Folder named Myfiles on the desktop
var f = Folder(Folder.desktop + "/MyFiles")
//get the files in MyFiles
var fl = f.getFiles()
for (var i = 0; i < fl.length; i++){
try {
fl[i].remove()
}catch(e) {}
};
@dublove said: "If fuzzy matching isn't possible, that would be highly unscientific.
$.writeln(File(Folder.desktop + “/Screen Shot*.*”).exists)"
Matching is possible, but not in the way you tried it.
Let's suppose there is a folder on your Desktop named "ScreenShots" containing, amongst other files and folders, also files where the name starts with "Screen Shot …" you could supply a filter function to getFiles() to part files from folders and match only files where the name begins with "Scree
...Copy link to clipboard
Copied
good idea
Copy link to clipboard
Copied
Well, also see the following reply to get the name of the machine on Windows or macOS (just in case):
How to get the windows username in jsx
கற_பன___Imagine_, Nov 11, 2011
https://community.adobe.com/t5/indesign-discussions/how-to-get-the-windows-username-in-jsx/m-p/35553...
Regards,
Uwe Laubender
( Adobe Community Expert )
Find more inspiration, events, and resources on the new Adobe Community
Explore Now