Highlighted

How to remove non-empty folder with framescript

Community Beginner ,
Jun 06, 2019

Copy link to clipboard

Copied

Hi

Do you know a way to remove a folder with files and folders with FrameScript.

FrameScript doesn't remove non - empty folders.

Thanks

TOPICS
Scripting

Views

887

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

How to remove non-empty folder with framescript

Community Beginner ,
Jun 06, 2019

Copy link to clipboard

Copied

Hi

Do you know a way to remove a folder with files and folders with FrameScript.

FrameScript doesn't remove non - empty folders.

Thanks

TOPICS
Scripting

Views

888

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
Jun 06, 2019 0
Engaged ,
Jun 06, 2019

Copy link to clipboard

Copied

Hi,

you need to traverse folder hierarchy, delete files in any folder, and after that you can delete folders.

Markus

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...
Jun 06, 2019 0
Community Beginner ,
Jun 06, 2019

Copy link to clipboard

Copied

Hi Markus,

thanks, can you suggest a way how can i check it's a directory or a 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...
Jun 06, 2019 0
Engaged ,
Jun 06, 2019

Copy link to clipboard

Copied

sure 😉

    function DeleteDirectory(srcFolder)

    {

        var currentFolder = srcFolder ;

        var files = currentFolder.getFiles("*") ;

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

        {

            if (typeof(files.copy) == "undefined")

            {

                //Delete recursively

                DeleteDirectory(files) ;

                files.remove() ;

            }

            else

            {

                files.remove();

            }

        }

        currentFolder.remove() ;

    }

Please note: Parameter of srcFolder must be of Type Folder...

Call for root folder is something like that:

DeleteDiretory(new Folder("Path to dir to remove"));

This should work. Good luck

Markus

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...
Jun 06, 2019 1
Community Beginner ,
Jun 06, 2019

Copy link to clipboard

Copied

Hi Markus,

but this is a extendscript, i need a framescript.  thanks

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...
Jun 06, 2019 0
Engaged ,
Jun 06, 2019

Copy link to clipboard

Copied

Hi,

this due to this is an ExtendScript forum.

Sorry, can't support you with FrameScript.

But may be you can port the logic.

Markus

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...
Jun 06, 2019 0
Participant ,
Jun 06, 2019

Copy link to clipboard

Copied

Hi Markus,

I see you call DeleteDirectory whithin its own definition (line 10). Not clear how it works.

Thanks,

Roman

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...
Jun 06, 2019 0
Engaged ,
Jun 06, 2019

Copy link to clipboard

Copied

Hi Roman,

getFiles(*) delivers any content in this Folder, means sub-folders and files.

To check if an item in file-list is a directory, I check if this object has a copy-method (typeof(files.copy)=="undefined"). As only File objects have a copy-method, and File object with no copy-method is a sub-folder and I call DeleteDirectory for subfolders recursivly, delete files there and after that folder itself is deleted.

When all sub-folders are deleted, root folder is deleted

Hope this helps

Markus

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...
Jun 06, 2019 0
Advocate ,
Jun 06, 2019

Copy link to clipboard

Copied

I normally use a test on constructor.name - which is safer than testing for the copy method (a newer version of ExtendScript might actually introduce the copy method for a folder - who knows?).

if( files.constructor.name == "Folder" ) -- this does the actual test you want to do.

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...
Jun 06, 2019 1
Engaged ,
Jun 06, 2019

Copy link to clipboard

Copied

Hi Jang,

thanks for pointing me that way.

I wasn't aware of this way till I saw it one of your last sample Code.

That's the better way to check this, of course.

Markus

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...
Jun 06, 2019 0