パスワードを忘れた? アカウント作成
10552264 journal
MacOSX

t-nissieの日記: 【電脳】Mac OS Xでファイルとディレクトリの拡張属性xattrを再帰的にすべて消す高速なPythonスクリプト 1

日記 by t-nissie

ここに置いてあったやつ,ディレクトリの拡張属性が消えないというバグがあったので,最新版を再掲.
Gistに置いたので,明日からはそっちでアップデートしていきます.

行頭のタブが消えないとよいのだけど:

#!/usr/bin/env python
# delxattr.py recursively removes all extended attributes (xattr) from
# all files and directories under the current or given directory.
# Time-stamp: <2014-01-18 22:09:43 t-nissie>
# Author: Takeshi NISHIMATSU
# 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()

dnames+fnamesにしないとダメだった.
fnamesだけのときはディレクトリ単体がリストの中に入らなかった.

この議論は賞味期限が切れたので、アーカイブ化されています。 新たにコメントを付けることはできません。
typodupeerror

日本発のオープンソースソフトウェアは42件 -- ある官僚

読み込み中...