forked from SABERBOY/CocosCreator3DPlayable
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_test.go
More file actions
53 lines (46 loc) · 809 Bytes
/
main_test.go
File metadata and controls
53 lines (46 loc) · 809 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"io/ioutil"
"os"
"testing"
)
// 删除所有空文件夹
func TestDelEmptyDir(t *testing.T) {
dir := "/Library/WebServer/Documents/game/test"
DelEmptyDir(dir)
}
func DelEmptyDir(dir string) (bool, error) {
list, err := ioutil.ReadDir(dir)
if err != nil {
return false, err
}
// 确定文件夹内部文件数量
l := len(list)
path := ""
for _, info := range list {
path = dir + string(os.PathSeparator) + info.Name()
if !info.IsDir() && info.Name() == ".DS_Store" {
err := os.Remove(path)
if err != nil {
continue
}
l--
continue
}
if !info.IsDir() {
continue
}
b, err := DelEmptyDir(path)
if err != nil {
continue
}
if b {
err := os.Remove(path)
if err != nil {
continue
}
l--
}
}
return l == 0, nil
}