My directory structure is as below:
dir -| | - sub_dir1 -| | | | - file1 | - sub_dir2 -| | | | - file2 | - sub_dir3 -| | - file3
I want to recursively delete all content of
dir except content of
So the expected resulting directory structure should be as below:
dir -| | - sub_dir1 -| | - file1
I have tried following code and it deleting all the files except the content of
sub_dir1. However it is not deleting the other sub directories but only the files within those directories.
delete fileTree(dir: "dir1").exclude("sub_dir1").include('**/**')
Result of above code:
dir -| | - sub_dir1 -| | | | - file1 | - sub_dir2 | | - sub_dir3
How can I delete these directories too along with the files contained by them?