Copy link to clipboard
Copied
Hello,
to change template, I'm trying to use ESTK scripts.
I made scripts
This requires "recursion" in order to work your way down the file/folder structure. Recursion is where a function calls itself. Here is an example that doesn't do any copying, but just writes the file and folder names from your source folder and subfolders to the FrameMaker Console. I will try to post a version that actually copies, but this will give you concept of touching each file and folder. You will have to edit the code and put in your own source and destination folders.
#target frame
...
Copy link to clipboard
Copied
This requires "recursion" in order to work your way down the file/folder structure. Recursion is where a function calls itself. Here is an example that doesn't do any copying, but just writes the file and folder names from your source folder and subfolders to the FrameMaker Console. I will try to post a version that actually copies, but this will give you concept of touching each file and folder. You will have to edit the code and put in your own source and destination folders.
#target framemaker
var sourceFolder, destinationFolder;
sourceFolder = new Folder ("C:\\DATA-10\\Scripts\\ArtCampbell\\20240205-TitleCase");
destinationFolder = new Folder ("C:\\DATA-10\\Scripts\\ArtCampbell\\Copy");
processFolder (sourceFolder);
function processFolder (sourceFolder, destinationFolder) {
var files, count, i;
files = sourceFolder.getFiles ();
count = files.length;
for (i = 0; i < count; i += 1) {
if (files[i] instanceof Folder) {
Console ("folder: " + files[i].fsName);
// Recursive call to this function:
processFolder (files[i], destinationFolder);
}
else {
Console ("* " + files[i].fsName);
}
}
}
Copy link to clipboard
Copied
This version actually does the copying and creates target folders where necessary. I renamed the destinationFolder variable to targetFolder.
var sourceFolder, targetFolder;
sourceFolder = new Folder ("C:\\DATA-10\\Scripts\\ArtCampbell\\20240205-TitleCase");
targetFolder = new Folder ("C:\\DATA-10\\Scripts\\ArtCampbell\\Copy");
processFolder (sourceFolder, targetFolder);
function processFolder (sourceFolder, targetFolder) {
var files, count, i, source, target;
// Get all of the files and folders from the source folder.
files = sourceFolder.getFiles ();
count = files.length;
for (i = 0; i < count; i += 1) {
// Get the source file object and its target object.
source = files[i];
target = new File (targetFolder.fsName + "\\" + source.name);
// See if the source is a File or Folder.
if (source instanceof File) {
// Copy the file to the target folder.
source.copy (target);
}
else { // Folder
target = new Folder (target);
// If the folder exists, call this function.
if (target.exists === true) {
processFolder (source, target);
}
else {
// Create the target folder and call this function.
if (target.create () === true) {
processFolder (source, target);
}
}
}
}
}
Copy link to clipboard
Copied
Thank you for tips, It really hepls me.
Have a nice day always.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now