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
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';
var copiedFile = copyFile(activeDocPath, copyToPath);
})();
/**
* Copies a file at `sourcePath` to `destinationPath`.
* @author m1b
* @version 2025-08-20
* @param {String} sourcePath - the source path.
* @param {String} destinationPath - the destination path.
* @returns {File}
*/
function copyFile(sourcePath, destinationPath) {
var f = File(sourcePath);
if (!f.exists)
throw new Error('File not found: "' + sourcePath + '".');
var dup = File(destinationPath);
f.copy(dup);
return dup;
};
Copy link to clipboard
Copied
I think I understand a little bit.
The difficulty may be obtaining the path.
C:\Users\olo\AppData\Roaming\Adobe\InDesign\Version 19.0-J\zh_CN\Find-Change Queries\GREP
I don't know how to get the “olo” here, and Version 19.0-J may also be Version 20.0-J.
It might be more practical to open the directory.
Then, manually copy and delete.
Copy link to clipboard
Copied
Can this function copy all files in the entire path?
Is there a delete function?
I want to copy all files to a specific path, such as aa, but nothing happens.
var copyToPath = Folder.desktop + ‘/aa/’;
Copy link to clipboard
Copied
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 other path shortcuts to commonly used system folders:
$.writeln("User Desktop: " + Folder.desktop)
//~/Desktop
$.writeln("System Application Support Folder: " + Folder.appData.fsName)
//System Application Folder: /Library/Application Support
$.writeln("User Application Support Folder: " + Folder.userData.fsName)
//User Application Support Folder: /Users/fishercat/Library/Application Support
$.writeln("Target Application Folder: " + Folder.appPackage.fsName)
//Target Application Folder: /Applications/Adobe InDesign 202X/Adobe InDesign 202X.app
$.writeln("Documents Folder: " + Folder.myDocuments)
//Documents Folder: ~/Documents
$.writeln("Application Startup Folder: " + Folder.startup.fsName)
//Application Startup Folder: /Applications/Adobe InDesign 2021/Adobe InDesign 2021.app/Contents/MacOS
$.writeln("System Folder: " + Folder.system)
//System Folder: /System
$.writeln("Temp Folder: " + Folder.temp.fsName)
//Temp Folder: /private/var/folders/w2/s1lk7d6d3m95v4pq7m4flscw0000gn/T/TemporaryItems
$.writeln("Trash Folder: " + Folder.trash)
//Trash Folder: ~/.Trash
Copy link to clipboard
Copied
Hi rob day.
I mainly want to access the following paths. The key point here is how to obtain “Version 19.0-J”.
C:\Users\olo\AppData\Roaming\Adobe\InDesign\Version 19.0-J\zh_CN\InDesign Shortcut Sets
C:\Users\olo\AppData\Roaming\Adobe\InDesign\Version 19.0-J\zh_CN\Find-Change Queries\GREP
C:\Users\olo\AppData\Roaming\Adobe\Adobe PDF\Settings
C:\Users\olo\AppData\Roaming\Adobe\InDesign\Version 19.0-J\zh_CN\Workspaces
How to delete files in a folder.
var copyToPath = new Folder(Folder.desktop + “/aa”);
copyToPath.create();
This seems to delete the aa directory, but I want to delete all the files under aa.
Copy link to clipboard
Copied
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 removes an InDesign file named IDFile.indd in the MyFiles folder
var f = File(dtf + "/IDFile.indd")
f.remove()
Copy link to clipboard
Copied
Can I only delete a specific file?
I want to delete any files and folders.
When copying, I also want to copy the files and folders under “Myfile/”.
var f = File(dtf + “/*.*”)
This does not seem to work.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Is there one for all documents?
I can't seem to find it.
Copy link to clipboard
Copied
@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 directory until it is empty..
You have to write your own function that traverses recursively all folders and subfolders of a "top hierarchy" folder to empty them before you can remove (delete) the top one…
Regards,
Uwe Laubender
( Adobe Community Expert )
Copy link to clipboard
Copied
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) {}
};
Copy link to clipboard
Copied
I've learned f.remove().
I raised another question.
Copying all files in the directory was unsuccessful.
I'm unsure how to express relative paths.
I can't manage to copy the entire directory.
Thank you very much.
Copy link to clipboard
Copied
"Can scripts in ID be used to copy or delete files?"
Hi @dublove ,
yes. So be very careful what you are doing.
( The right soundtrack to this: https://www.youtube.com/watch?v=V-HYayT1vwg&list=RDV-HYayT1vwg&start_radio=1 )
C:\Users\olo\AppData\Roaming\Adobe\InDesign\Version 19.0-J\zh_CN\Find-Change Queries\GREP
"I don't know how to get the “olo” here, and Version 19.0-J may also be Version 20.0-J."
See:
Writing an InDesign script to identify users
Laubender, Mar 26, 2020
And with ExtendScript there is no need to use backslashes in folder or file paths. Slashes will do.
On macOS and Windows.
Regards,
Uwe Laubender
( Adobe Community Expert )
Copy link to clipboard
Copied
How to obtain “Version 19.0-J”
This is not version number 19.5.
I have asked the following questions.
However, I still cannot directly obtain “Version 19.0-J.”
alert(app.scriptPreferences.version);
alert(app.scriptPreferences.scriptsFolder.parent.parent);
alert(app.scriptPreferences.scriptsFolder);
How to get the path of the regular?
C:\Users\adm\AppData\Roaming\Adobe\InDesign\Version 19.0-J\zh_CN\Find-Change Queries\Text
There are also shortcuts stored in the path
C:\Users\adm\AppData\Roaming\Adobe\InDesign\Version 19.0-J\zh_CN\InDesign Shortcut Sets
Workspace Path
C:\Users\adm\AppData\Roaming\Adobe\InDesign\Version 19.0-J\zh_CN\Workspaces
PDF Export Template Path
C:\Users\adm\AppData\Roaming\Adobe\Adobe PDF\Settings
Copy link to clipboard
Copied
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 )
Copy link to clipboard
Copied
Can you access this location?
C:\Users\olo\AppData\Local\Adobe\InDesign\Version 19.0 - J\zh_CN\Caches
C:\Users\olo\AppData\Roaming\Adobe\Adobe PDF\Settings
Copy link to clipboard
Copied
On MacOS it’s the parent folder of appData (the user’s Library folder):
$.writeln(Folder.appData.parent + "/Preferences/Adobe InDesign/Version 19.0")
// /Library/Preferences/Adobe InDesign/Version 19.0
$.writeln(Folder.appData.parent + "/Application Support/Adobe/Adobe PDF")
// /Library/Application Support/Adobe/Adobe PDF
Copy link to clipboard
Copied
The version number may vary.
Copy link to clipboard
Copied
You would have to test for that in your code
Copy link to clipboard
Copied
var f = File(dtf + "/IDFile.indd")
f.remove()
What should you do if part of the filename is unstable?
For example, it could be:
IDFile-2025.indd or IDFile-2023.indd or IDFile2024.indd
“IDFile” is confirmed.
Copy link to clipboard
Copied
What should you do if part of the filename is unstable?
You would have to test if the file exists. Here I have a file named Screen Shot 4.png on my desktop, which returns true, while Screen Shot 4 returns false
$.writeln(File(Folder.desktop + "/Screen Shot 4.png").exists)
//returns true
$.writeln(File(Folder.desktop + "/Screen Shot 4").exists)
//returns false
Copy link to clipboard
Copied
If fuzzy matching isn't possible, that would be highly unscientific.
$.writeln(File(Folder.desktop + “/Screen Shot*.*”).exists)
Similarly, copy(); does not support copying folders.
This feature is really disappointing.
Still, it's sufficient for most needs.
Copy link to clipboard
Copied
//$.writeln(File(Folder.desktop + “/Screen Shot*.*”).exists)
Use getFiles() with your search as the parameter
https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Folder.html
var f = Folder(Folder.userData.parent + "/Preferences/Adobe InDesign")
$.writeln(f.getFiles())
Copy link to clipboard
Copied
@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 "Screen Shot".
For example:
var myFolder = Folder( Folder.desktop +"/"+ "ScreenShots" +"/" );
var myFileListArray = myFolder.getFiles
(
function(file)
{
if
(
file instanceof File
&&
decodeURI( file.name ).match( /^Screen Shot/ )
&&
!file.hidden
)
return true
}
);
alert( myFileListArray.length );
Find more inspiration, events, and resources on the new Adobe Community
Explore Now