Last active
November 16, 2017 10:49
Star
You must be signed in to star a gist
[PYTHON] 指定したディレクトリ以下の全ファイルの読取り専用を外す (Windows)
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
""" | |
指定したディレクトリ以下の全ファイルの読取り専用を外します。 | |
デフォルトはカレントディレクトリを対象とします。 | |
""" | |
import os | |
import stat | |
DEFAULT_DIR = '.' | |
def execute(target_directory): | |
"""処理を実行します。""" | |
for root, dirs, files in os.walk(target_directory): | |
for file_name in files: | |
full_path = os.path.join(root, file_name) | |
if not os.access(full_path, os.W_OK): | |
os.chmod(full_path, stat.S_IWRITE) | |
if __name__ == '__main__': | |
execute(DEFAULT_DIR) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
参考情報
https://stackoverflow.com/questions/4829043/how-to-remove-read-only-attrib-directory-with-python-in-windows
https://stackoverflow.com/questions/2113427/determining-whether-a-directory-is-writeable