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
873
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
Guide ,
Sep 01, 2025 Sep 01, 2025
LATEST

good idea

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

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 )

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