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

How to remove non-empty folder with framescript

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

1.2K

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

Votes

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 Beginner ,
Jun 06, 2019 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 ?

Votes

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

Votes

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

Copy link to clipboard

Copied

Hi Markus,

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

Votes

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

Votes

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

Votes

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

Votes

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

Votes

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

Copy link to clipboard

Copied

LATEST

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

Votes

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