Guest User

Set Folder Icon

a guest
May 20th, 2017
233
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python3
  2. import subprocess
  3. import os
  4. import sys
  5.  
  6. # --- set the list of valid extensions below (lowercase)
  7. # --- use quotes, *don't* include the dot!
  8. ext = ["jpg", "jpeg", "png", "gif","icns", "ico"]
  9. # ---
  10.  
  11. dr = sys.argv[1]
  12.  
  13. for root, dirs, files in os.walk(dr):
  14.     for directory in dirs:
  15.         folder = os.path.join(root, directory)
  16.         try:
  17.             first = min(p for p in os.listdir(folder)
  18.                         if p.split(".")[-1].lower() in ext)
  19.         except ValueError:
  20.             pass
  21.         else:
  22.               subprocess.Popen([
  23.                   "gvfs-set-attribute", "-t", "string",
  24.                   os.path.abspath(folder), "metadata::custom-icon",
  25.                   "file://"+os.path.abspath(os.path.join(folder, first))
  26.                   ])
RAW Paste Data