Remove directories only command line

How to remove folders and there content and keep files in the current directory ?

before

parent
├── folder1
├── folder2
│   ├── file1
│   ├── file2
├── folder3
├── file3
├── file4
└── file5

after:

parent
├── file3
├── file4
└── file5

Solution 1:

Something like this should do the trick

cd parent
find . ! -path . -maxdepth 1 -type d -exec rm -rf {} \;

This will look for directories in the current working dir and only recurse 1 level down and the removes the dirs. Best do a testrun with ls instead of rm before doing this so you can check what will be removed

cd parent
find . ! -path . -maxdepth 1 -type d -exec ls {} \;

Example

jake@jake-HP /tmp/test $ tree
.
├── 1
├── 2
├── bar
│   ├── 1
│   ├── 2
│   └── 3
├── blah
│   ├── 1
│   ├── 2
│   └── 3
└── foo
    ├── 5
    └── 9

3 directories, 10 files
jake@jake-HP /tmp/test $ find . ! -path . -maxdepth 1 -type d -exec ls {} \;
1  2  bar  blah  foo
1  2  3
5  9
1  2  3
jake@jake-HP /tmp/test $ find . ! -path . -maxdepth 1 -type d -exec rm -rf {} \;
jake@jake-HP /tmp/test $ tree
.
├── 1
└── 2

0 directories, 2 files