Last active
January 1, 2016 23:19
-
-
Save rainyear/8215756 to your computer and use it in GitHub Desktop.
map a command(function) to all the files in current directory.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
#-*- coding:utf-8 -*- | |
""" | |
Walking the destination directory(arg3) and using the command(arg2) | |
to process every file. | |
USAGE: | |
Mapwalk `function` /path/to/walk | |
""" | |
import sys | |
reload(sys) | |
sys.setdefaultencoding('utf-8') | |
import os.path | |
def walk_dir(dir, cmd="", topdown=True): | |
for root, dirs, files in os.walk(dir, topdown): | |
for name in files: | |
opf = os.path.join(name) | |
exe = "%s '%s'" % (cmd, opf) | |
print exe | |
os.system(exe) | |
if __name__ == '__main__': | |
walk_dir("./", sys.argv[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
直接用find就可以了吧,find的过滤功能还更强大