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
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
Copy link to clipboard
Copied
Hi Markus,
thanks, can you suggest a way how can i check it's a directory or a file ?
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
Copy link to clipboard
Copied
Hi Markus,
but this is a extendscript, i need a framescript. thanks
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
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
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
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.
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