init commit.
This commit is contained in:
44
empty-dir.go
Normal file
44
empty-dir.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func emptyDir(p string) {
|
||||
files, err := os.ReadDir(p)
|
||||
if err != nil && strings.Contains(err.Error(), "Access is denied") {
|
||||
remindErr(err)
|
||||
return
|
||||
}
|
||||
|
||||
PanicErr(err)
|
||||
|
||||
defer func() {
|
||||
remainFiles, e := os.ReadDir(p)
|
||||
PanicErr(e)
|
||||
|
||||
if len(remainFiles) == 0 {
|
||||
e = Rm(p)
|
||||
remindErr(e)
|
||||
}
|
||||
}()
|
||||
|
||||
for _, file := range files {
|
||||
filePath := filepath.Join(p, file.Name())
|
||||
if !file.IsDir() {
|
||||
if strings.HasPrefix(file.Name(), "._") && IsMacMetaFile(filePath) {
|
||||
err = Rm(filePath)
|
||||
remindErr(err)
|
||||
} else if file.Name() == ".DS_Store" {
|
||||
err = Rm(filePath)
|
||||
remindErr(err)
|
||||
}
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
emptyDir(filePath)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user