Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@jarun
Created October 4, 2017 20:55
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jarun/2bcb5238bc47111c22f783254a98fd5d to your computer and use it in GitHub Desktop.
Save jarun/2bcb5238bc47111c22f783254a98fd5d to your computer and use it in GitHub Desktop.
Remove executable permission for media files recursively
#!/usr/bin/env python3
import os
import stat
extns = ['.aac', '.avi', '.flac', '.m3u', '.m4a', '.mkv', '.mp3', '.mp4', '.smi', '.srt', '.sub', '.webm', '.wma']
for root, dirs, files in os.walk('.'):
for entry in files:
fname, ext = os.path.splitext(entry)
ext = ext.lower()
if ext in extns:
abspath = os.path.join(root, entry)
if os.access(abspath, os.X_OK):
fperms = stat.S_IMODE(os.lstat(abspath).st_mode)
os.chmod(abspath, fperms & ~stat.S_IXUSR & ~stat.S_IXGRP & ~stat.S_IXOTH)
print(abspath)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment