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

Copy Files alongwith Folders

Community Beginner ,
Jul 01, 2013 Jul 01, 2013

Hi Forum!

I have this bit of script to copy files which resides inside the Folder.

My request to forum, is to get help, to copy all the contents inside the folder...

contents inside the folder, can be *.indd, *.zip, *.tif, *.eps etc., and also the folders inside the folders and its contents..

Currently I can only able to copy only the files (*.*) inside the folder and cant able to copy the folder inside the folder and its files...

var copyFolder1 = Folder('/Users/admin/Desktop/LZW/For General');

var pasteFolder1 = Folder('/Volumes/CTC/Normal/MyFiles');

var myFiles2 = copyFolder1.getFiles( '*.*');

for ( i = myFiles2.length-1; i >= 0 ; i-- ){

var myResult = myFiles2.copy(pasteFolder1 +"/" + myFiles2.name);

}

Please can I get help to do this.

thanks & rgs.

TOPICS
Scripting
3.8K
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 1 Correct answer

Explorer , Jul 02, 2013 Jul 02, 2013

Just change the first line to choose the correct folders.

copyFolder(new Folder("C:/Source Folder"), new Folder("C:/Destination Folder"));

function copyFolder(sourceFolder, destinationFolder) {

    var sourceChildrenArr = sourceFolder.getFiles();

    for (var i = 0; i < sourceChildrenArr.length; i++) {

        var sourceChild = sourceChildrenArr;

        var destinationChildStr = destinationFolder.fsName + "/" + sourceChild.name;

        if (sourceChild instanceof File) {

            copyFile(sourceChil

...
Translate
Community Beginner ,
Jul 01, 2013 Jul 01, 2013

Well, I have this too.

But the problem is I can't able to do copy..

var myObject = new ActiveXObject("Scripting.FileSystemObject");

    var myFolder = myObject.GetFolder("/Users/admin/Desktop/LZW/For General");

    myFolder.Copy("/Volumes/CTC/Normal/MyFiles", true);

Result while runnig script is :ActiveXObject does not have a constructor.

Please help!... and advance thanks to forum...

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 Beginner ,
Jul 02, 2013 Jul 02, 2013

HI Forum,

Does my request make sense! Please forgive me if not.

Because I'm not interestingly trying with the actual java code and not even i'm familiar with too.

Will be much appreciated, to get it help on any other way to copy the entire folder and its contents.

thanks in advance..

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
Explorer ,
Jul 02, 2013 Jul 02, 2013

Just change the first line to choose the correct folders.

copyFolder(new Folder("C:/Source Folder"), new Folder("C:/Destination Folder"));

function copyFolder(sourceFolder, destinationFolder) {

    var sourceChildrenArr = sourceFolder.getFiles();

    for (var i = 0; i < sourceChildrenArr.length; i++) {

        var sourceChild = sourceChildrenArr;

        var destinationChildStr = destinationFolder.fsName + "/" + sourceChild.name;

        if (sourceChild instanceof File) {

            copyFile(sourceChild, new File(destinationChildStr));

        }

        else {

            copyFolder(sourceChild, new Folder(destinationChildStr));

        }

    }

}

function copyFile(sourceFile, destinationFile) {

    createFolder(destinationFile.parent);

    sourceFile.copy(destinationFile);

}

function createFolder(folder) {

    if (folder.parent !== null && !folder.parent.exists) {

        createFolder(folder.parent);

    }

    folder.create();

}

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 Beginner ,
Jul 03, 2013 Jul 03, 2013

Really helpfull dln385,

Thanks so much for your inpurt to meet my request.

I shall be checking withing an hour and let you know if any doubt arouses.

thanks you so 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 Beginner ,
Jul 03, 2013 Jul 03, 2013

superb dln385,

Really helpfull dln385,

Can i know, any reference links for creating these kind of complicated scripts.

Would be greatfull to you, if i have the reference.

thanks so much for the stuff....

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
Explorer ,
Jul 03, 2013 Jul 03, 2013

ExtendScript is mostly JavaScript. First learn JavaScript.

Then learn ExtendScript.

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
Enthusiast ,
Jul 05, 2013 Jul 05, 2013
LATEST

In addition to the full answer you could take a note that "ActiveXObject" is not supported by the ExtendScript javascript used by InDesign. Instead a separate set of File handling objects/methods is implemented, that works for MacOS and Windows. ActiveXObject is probably windows specific.

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