Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Can scripts in ID be used to copy or delete files?

Guide ,
Aug 20, 2025 Aug 20, 2025

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.

60000.png

TOPICS
How to , Scripting
786
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 7 Correct answers

Community Expert , Aug 20, 2025 Aug 20, 2025

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';

 
...
Translate
Community Expert , Aug 20, 2025 Aug 20, 2025

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 )

Translate
Community Expert , Aug 20, 2025 Aug 20, 2025

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)

 

Screen Shot 8.png

 

To create a folder:

var copyToPath = new Folder(Folder.desktop + "/aa");
copyToPath.create();

 

To delete the folder:

copyToPath.remove();

Also there are

...
Translate
Community Expert , Aug 21, 2025 Aug 21, 2025

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 
...
Translate
Community Expert , Aug 21, 2025 Aug 21, 2025

@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

...
Translate
Community Expert , Aug 21, 2025 Aug 21, 2025

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) {}  
};  
Translate
Community Expert , Sep 01, 2025 Sep 01, 2025

@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

...
Translate
Community Expert ,
Aug 20, 2025 Aug 20, 2025

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;

};
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Aug 20, 2025 Aug 20, 2025

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Aug 20, 2025 Aug 20, 2025

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/’;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 20, 2025 Aug 20, 2025

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)

 

Screen Shot 8.png

 

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

 

 

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Aug 20, 2025 Aug 20, 2025

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 21, 2025 Aug 21, 2025

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()
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Aug 21, 2025 Aug 21, 2025

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.

dublove_0-1755788641490.jpeg

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 21, 2025 Aug 21, 2025
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Aug 21, 2025 Aug 21, 2025

Is there one for all documents?
I can't seem to find it.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 21, 2025 Aug 21, 2025

@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 )

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 21, 2025 Aug 21, 2025

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) {}  
};  
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Aug 28, 2025 Aug 28, 2025

@Laubender 

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.

https://community.adobe.com/t5/indesign-discussions/is-it-possible-to-copy-all-files-under-a-specifi...


I can't manage to copy the entire directory.

Thank you very much.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 20, 2025 Aug 20, 2025

"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

https://community.adobe.com/t5/indesign-discussions/writing-an-indesign-script-to-identify-users/m-p...

 

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 )

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Aug 20, 2025 Aug 20, 2025

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 20, 2025 Aug 20, 2025

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 )

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Aug 29, 2025 Aug 29, 2025

@Laubender 

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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 29, 2025 Aug 29, 2025

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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Aug 29, 2025 Aug 29, 2025

The version number may vary.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 30, 2025 Aug 30, 2025

You would have to test for that in your code

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Aug 30, 2025 Aug 30, 2025
var f = File(dtf + "/IDFile.indd")
f.remove()

@rob day 

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.

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 31, 2025 Aug 31, 2025

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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Aug 31, 2025 Aug 31, 2025

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 31, 2025 Aug 31, 2025

//$.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())

 

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 01, 2025 Sep 01, 2025

@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 );

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines