Skip to content

Instantly share code, notes, and snippets.

@devlights
Last active November 16, 2017 10:49
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save devlights/f6bf40fa42e8893e68305976e6b766b8 to your computer and use it in GitHub Desktop.
[PYTHON] 指定したディレクトリ以下の全ファイルの読取り専用を外す (Windows)
"""
指定したディレクトリ以下の全ファイルの読取り専用を外します。
デフォルトはカレントディレクトリを対象とします。
"""
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)