Highlighted

Is it possible to copy folder with Extendscript

New Here ,
Feb 07, 2017

Copy link to clipboard

Copied

Not sure if this is only available to files... Trying to create a folder locally (C: drive) and then copy the folder (and contents) to another folder on the network...

var foSource = new Folder(myPath);

foSource.copy(strTarget);

This throws an error... any ideas?

Thanks!

Hi funsekon,

here's one way to do that:

var NewFileName;

var oFiles;

var oNewFolder

var StartFolder = "C:\\temp";   // preselection for Windows Explorer

var locFolder = new Folder(StartFolder);

var oOldFolder = locFolder.selectDlg ("Folder");

    

if (oOldFolder != null)

    {

       

    oNewFolder = new Folder(oOldFolder + "\\NewFolder") ;

    if (oNewFolder.exists)

        {

        // alert("overwrite?")

        // ......

        }

    else

        {

        oNewFolder.create();

        }

   

        oFiles = oOldFolder.getFiles ("*.fm");

   

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

            {

             NewFileName =    oFiles.fsName.replace(oOldFolder.fsName,oNewFolder.fsName);

            oFiles.copy(NewFileName);

            }

}

TOPICS
Scripting

Views

1.2K

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

Is it possible to copy folder with Extendscript

New Here ,
Feb 07, 2017

Copy link to clipboard

Copied

Not sure if this is only available to files... Trying to create a folder locally (C: drive) and then copy the folder (and contents) to another folder on the network...

var foSource = new Folder(myPath);

foSource.copy(strTarget);

This throws an error... any ideas?

Thanks!

Hi funsekon,

here's one way to do that:

var NewFileName;

var oFiles;

var oNewFolder

var StartFolder = "C:\\temp";   // preselection for Windows Explorer

var locFolder = new Folder(StartFolder);

var oOldFolder = locFolder.selectDlg ("Folder");

    

if (oOldFolder != null)

    {

       

    oNewFolder = new Folder(oOldFolder + "\\NewFolder") ;

    if (oNewFolder.exists)

        {

        // alert("overwrite?")

        // ......

        }

    else

        {

        oNewFolder.create();

        }

   

        oFiles = oOldFolder.getFiles ("*.fm");

   

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

            {

             NewFileName =    oFiles.fsName.replace(oOldFolder.fsName,oNewFolder.fsName);

            oFiles.copy(NewFileName);

            }

}

TOPICS
Scripting

Views

1.2K

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
Feb 07, 2017 0
Enthusiast ,
Feb 07, 2017

Copy link to clipboard

Copied

What is your "strTarget"?

How is it build?  It should be something like "C:\\Users\\User\\MyFolder";

IMPORTANT: backslash must be double( means: masked)

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
Reply
Loading...
Feb 07, 2017 0
Enthusiast ,
Feb 07, 2017

Copy link to clipboard

Copied

It may be because the Folder object does not have a copy() function.

I had a quick look at this and I believe that you will have to create your own recursive folder copy function. That will need to create a new folder, then copy each file into it. A recursive function will allow it to also create/copy sub-folders.

By the way, I normally use URI notation for all paths as it saves all that double backslash nonsense and it's how the File and Folder objects store the paths anyway.

Ian

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
Reply
Loading...
Feb 07, 2017 0
Enthusiast ,
Feb 07, 2017

Copy link to clipboard

Copied

Hi Ian,

you're absolutely right.

Only a file can be copied, but not a folder.

@funsekon: You have to create the (sub-)folder and copy the FILES.( file by file)

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
Reply
Loading...
Feb 07, 2017 0
Enthusiast ,
Feb 07, 2017

Copy link to clipboard

Copied

Hi funsekon,

here's one way to do that:

var NewFileName;

var oFiles;

var oNewFolder

var StartFolder = "C:\\temp";   // preselection for Windows Explorer

var locFolder = new Folder(StartFolder);

var oOldFolder = locFolder.selectDlg ("Folder");

    

if (oOldFolder != null)

    {

       

    oNewFolder = new Folder(oOldFolder + "\\NewFolder") ;

    if (oNewFolder.exists)

        {

        // alert("overwrite?")

        // ......

        }

    else

        {

        oNewFolder.create();

        }

   

        oFiles = oOldFolder.getFiles ("*.fm");

   

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

            {

             NewFileName =    oFiles.fsName.replace(oOldFolder.fsName,oNewFolder.fsName);

            oFiles.copy(NewFileName);

            }

}

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
Reply
Loading...
Feb 07, 2017 0
funsekon LATEST
New Here ,
Feb 08, 2017

Copy link to clipboard

Copied

Thanks Klaus, this procedure works wonders. Yes, my target folder looks like: "C:\\Users\\User\\MyFolder";

Thanks @Ian Proudfoot for your suggestions and comments...

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
Reply
Loading...
Feb 08, 2017 0