使用go和python递归删除.ds store文件的方法
2014-01-22 00:00
836 查看
python版本:
go语言版本:
#!/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语言版本:
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\n total number:%d\n", count) }
相关文章推荐
- 使用go和python递归删除.ds store文件的方法
- mac os去除去除.DS_Store文件--使用python和go(原创)
- 如何使用python递归查找并删除某个目录下的文件
- 递归的一些方法使用:深度遍历路径中的所有文件和目录,删除一个有文件的文件夹
- PHP 使用递归方法删除目录及目录下文件
- 使用python读取txt文件的内容,并删除重复的行数方法
- 如何删除Mac系统里面的所有 DS_Store 文件
- Eclipse恢复已删除的文件和代码、svn使用了还原,但本地的没有提交找回没提交代码的方法
- Python删除空文件和空文件夹的方法
- Linux下使用rsync最快速删除海量文件的方法。
- Mac删除所有DS_store文件
- Linux下使用rsync最快速删除海量文件的方法
- 用PHP脚本删除MAC系统的.DS_Store文件
- python制作exe可执行文件的方法---使用pyinstaller
- python删除特定文件的方法
- 使用Python删除Windows中只读文件
- python使用wxPython打开并播放wav文件的方法
- Java使用File的的delete()方法删除文件
- Python利用递归实现文件的复制方法
- 在Python程序中操作文件之isatty()方法的使用教程