Remove. DS_Store files from mac OS-use python and go (original)

Source: Internet
Author: User

. 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?

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.