. DS_Store is a hidden file created by Apple's Mac OS X operating system. It stores custom properties of folders, for example, you can select the icon position or background color of a file. -- See Wikipedia
Sometimes ,. DS_Store is especially troublesome, such as compressing files or using version control software such as svn and git, so a piece of code is written for Recursive deletion. DS_Store file. The younger brother is the first programmer. The code here is only the first version. Please give me some advice.
Python version:
#! /Usr/bin/env pythonimport OS, sys; def walk (path): print "cd directory:" + path for item in OS. listdir (path): try: if (item = ". DS_Store "): global 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" character t 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: 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 total number: % d \ n", count)} Finally, this is the first blog. I don't know how to use the code editor of the blog garden. Could you please advise?