Move or copy files from one location(folder) to another using JSX

Community Beginner ,
Sep 14, 2022 Sep 14, 2022

Copy link to clipboard

Copied

How to Move or copy files from one location(folder) to another using JSX?

TOPICS
Scripting

Views

59

Likes

Translate

Translate

Report

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 14, 2022 Sep 14, 2022

Copy link to clipboard

Copied

Extendscript does not seem to have a move function but it does have a copy and remove function. You can mock move by first copying and then deleting. For details on the api's see the following

https://www.indesignjs.de/extendscriptAPI/illustrator-latest/#File.html

-Manan

Likes

Translate

Translate

Report

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
Contributor ,
Sep 14, 2022 Sep 14, 2022

Copy link to clipboard

Copied

LATEST

Pretty straightforward using ExtendScript File objects (learn more here).

 

// file you want to copy
var sourceFile = new File("/some-folder-path/file-to-copy.ai");
// where you want to copy the file to
var targetFile = new File("/folder-path-to-copy-to/copied-file.ai");
// copy the source file to the target location
sourceFile.copy(targetFile);
// delete the source file
sourceFile.remove();

 

A few notes about the code above...

  • I would include some error checking to make sure the target folder exists
  • I would also check to make sure the copy location didn't already have a file by the same name as the copy method overwrites without confirmation

Likes

Translate

Translate

Report

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