3

How can I change the icons of many folders?

How to set the first picture of every folders as their folder icons?

I've been here but it doesn't work for me. Because my movies aren't in the home partition they are in a different ext4 partition and when I try to put the location of that partition in that command it simply doesn't work because it automatically puts /home/sumeet in front of the location that I type.

Scripts in the 2nd post aren't working! Maybe I'm doing something wrong.

[EDIT 2 DETAILED]

{ while read -r d ; do [ -d "$d" ] && [ -e "$d/folder.png" ] || continue ; gvfs-set-attribute -t string "$d" metadata::custom-icon "file://$d/folder.png" ; done ; } < <(find ~/mnt/c2104e2a-cc8e-4b7b-9bba-a05d316472b4/I -mindepth 1 -maxdepth 1 -type d)

I ran this command first from the first post, which gave me an out put

find: ‘/home/sumeet/mnt/c2104e2a-cc8e-4b7b-9bba-a05d316472b4/I’: No such file or directory

Then I moved some of the files to home/videos/films as suggested in the orignal post and ran this command

{ while read -r d ; do [ -d "$d" ] && [ -e "$d/folder.png" ] || continue ; gvfs-set-attribute -t string "$d" metadata::custom-icon "file://$d/folder.png" ; done ; } < <(find ~/Videos/Films -mindepth 1 -maxdepth 1 -type d)

Which worked perfectly fine but i can't move my entire film collection to home folder.

Then I tried the solution in the 2nd mentioned post and ran

python3 /home/sumeet/change_icon.py </mnt/c2104e2a-cc8e-4b7b-9bba-a05d316472b4/I>

And got this output

bash: syntax error near unexpected token `newline'

Then I figured, I did something wrong and tried this

python3 /home/sumeet/change_icon.py /mnt/c2104e2a-cc8e-4b7b-9bba-a05d316472b4/I

Didn't get any output but it didn't work either.

Then I tried the second script 3 or 4 times. Right click option appeared but it didn't work, and I've done everything both the posts asked. I logged out, logged back in, I tried rebooting, -q nautilus

Doesn't seem to be working.

Zanna
  • 70,465

1 Answers1

6

This script was written by Jacob Vlijm and was originally posted here.

#!/usr/bin/env python3
import subprocess
import os

# --- set the list of valid extensions below (lowercase)
# --- use quotes, *don't* include the dot!
ext = ["jpg", "jpeg", "png", "gif", "icns", "ico"]
# ---

# retrieve the path of the targeted folder
current = os.getenv("NAUTILUS_SCRIPT_CURRENT_URI").replace("file://", "").replace("%20", " ")
dr = os.path.realpath(current)

for root, dirs, files in os.walk(dr):
    for directory in dirs:
        folder = os.path.join(root, directory)
        try:
            first = min(p for p in os.listdir(folder) 
                        if p.split(".")[-1].lower() in ext)
        except ValueError:
            pass
        else:
              subprocess.Popen([
                  "gvfs-set-attribute", "-t", "string",
                  os.path.abspath(folder), "metadata::custom-icon",
                  "file://"+os.path.abspath(os.path.join(folder, first))
                  ])

To use

  1. Create, if it doesn't exist yet, the directory

    ~/.local/share/nautilus/scripts
    
  2. Copy the script into an empty file, save it in ~/.local/share/nautilus/scripts as set_foldericons (no extension!), right click and go to file properties and make it executable.

  3. Log out and back in, it works.

If you want to hide all the folder icons (so that you don't accidentally presume they are folders) add a . at the start of file names, for example folder.png becomes .folder.png

all set, with one script

Original work