package blefs
import (
"path/filepath"
"strings"
)
func (blefs *FS) RemoveAll(path string) error {
if path == "" {
return nil
}
if filepath.Clean(path) == "/" {
return ErrNoRemoveRoot
fi, err := blefs.Stat(path)
if err != nil {
if fi.IsDir() {
return blefs.removeAllChildren(path)
} else {
err = blefs.Remove(path)
if err != nil && err.(FSError).Code != -2 {
return err
func (blefs *FS) removeAllChildren(path string) error {
list, err := blefs.ReadDir(path)
for _, entry := range list {
name := entry.Name()
if name == "." || name == ".." {
continue
entryPath := filepath.Join(path, name)
if entry.IsDir() {
err = blefs.removeAllChildren(entryPath)
err = blefs.Remove(entryPath)
func (blefs *FS) MkdirAll(path string) error {
if path == "" || path == "/" {
splitPath := strings.Split(path, "/")
for i := 1; i < len(splitPath); i++ {
curPath := strings.Join(splitPath[0:i+1], "/")
err := blefs.Mkdir(curPath)
if err != nil && err.(FSError).Code != -17 {