Python version:
Copy Code code as follows:
#!/usr/bin/env python
import OS, sys;
def walk (Path):
Print "CD directory:" +path
For item in Os.listdir (path):
Try
if (item = =.) Ds_store "):
Global Count
Count = count+1
Print "Find file. Ds_store "
Os.remove (path+ "/" +item)
Else
if (Os.path.isdir (path+ "/" +item)):
Print "+path+"/"+item+" is directory
Walk (path+ "/" +item)
Else
Print "+path+"/"+item+" is file
Except Oserror,e:
Print E
If __name__== ' __main__ ':
Count = 0
if (Len (SYS.ARGV) >1):
Root_dir = sys.argv[1]
Else
Root_dir = OS.GETCWD ()
Walk (Root_dir)
Print "\ntotal number:" +str (count)
Go language version:
Copy Code code as follows:
Package Main
Import (
"Flag"
"FMT"
"OS"
"Path/filepath"
)
Func getfilelist (path string) int {
Count: = 0
ERR: = FilePath. Walk (Path, func (path string, f OS). FileInfo, err Error) error {
if f = = nil {
return err
}
If F.isdir () {
Fmt. Printf ("CD directry%s\n", Path)
return Nil
}
If f.name () = = ". Ds_store "{
count++
println ("" + f.name () + "is deleted")
Os. Remove (PATH)
}
return Nil
})
If Err!= nil {
Fmt. Printf ("filepath. Walk () returned%v\n ", err)
}
return count
}
Func Main () {
Flag. Parse ()
Root: = flag. ARG (0)
Count: = 0
if root = = "" {
Crurrent_dir, _: = FilePath. Abs (".")
Count = Getfilelist (Crurrent_dir)
} else {
Count = getfilelist (root)
}
Fmt. Printf ("\ n \ nthe total number:%d\n", count)
}