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

How to remove non-empty folder with framescript

Community Beginner ,
Jun 06, 2019 Jun 06, 2019

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

Hi,

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

Markus

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

Hi Markus,

thanks, can you suggest a way how can i check it's a directory or a file ?

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

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

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

Hi Markus,

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

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

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

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

Hi Markus,

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

Thanks,

Roman

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

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

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

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.

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

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