Last active
June 6, 2016 02:37
-
-
Save t-nissie/8491009 to your computer and use it in GitHub Desktop.
Mac OS Xとかでファイルとディレクトリの拡張属性xattrを再帰的にすべて消す高速なPythonスクリプトdelxattr.py
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 | |
# delxattr.py recursively removes all extended attributes (xattr) from | |
# all files and directories under the current or given directory. | |
# In the latest Mac OS X, you can do the same thing with "xattr -rc". | |
# See a help of xattr with "xattr -h". | |
# Author: Takeshi NISHIMATSU | |
# Gist: https://gist.github.com/t-nissie/8491009 | |
# Example1$ delxattr.py | |
# Example2$ delxattr.py ../foo | |
# Example3$ delxattr.py ~/foo | |
# Example4$ delxattr.py /tmp/foo/bar | |
# Copying: delxattr.py is distributed in the hope that it will be | |
# useful, but WITHOUT ANY WARRANTY. You can copy, modify and | |
# redistribute delxattr.py, but only under the conditions described | |
# in the GNU General Public License (the "GPL"). For more detail, | |
# see http://www.gnu.org/licenses/gpl.html . | |
## | |
import sys | |
import os | |
import xattr | |
try: | |
dir = sys.argv[1] | |
except IndexError: | |
dir = "." | |
for dpath,dnames,fnames in os.walk(dir): | |
for fname in dnames+fnames: | |
f = os.path.join(dpath,fname) | |
if os.path.islink(f): | |
continue | |
xattr.xattr(f).clear() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment