[SOLVED] - Solution for Folder Icon

Please post suggestions for improvement of Cinnamon on:
https://github.com/linuxmint/Cinnamon
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
Locked
rahulkundu4u

[SOLVED] - Solution for Folder Icon

Post by rahulkundu4u »

Hi,

I am using Linux Mint 19.1 Cinnamon Desktop. I have 3 drive partitions. First one for Linux Mint os and other two for general purpose storage (NTFS Formatted).

In the storage drive every folder I want to use a different icon, this helps me to identify the folder easily. I know that I can change folder icon by right-clicking and then clicking the property. But the problem is here once I format the OS(Just like I did yesterday to upgrade from LM 18.2 to 19.1) all icons are gone.

What I want is to keep the folder icon inside each folder and the folder should automatically apply the icon. In this way, the folder icon will be kept intact even I format the os or copy the folders to an external HDD.

I am a novice Linux user and it will be great if someone helps me.
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 4 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
rene
Level 20
Level 20
Posts: 12212
Joined: Sun Mar 27, 2016 6:58 pm

Re: Solution for Folder Icon

Post by rene »

As fas as I'm aware not any of the usual Linux desktop file managers will/can do this out of the box. However, your want coincides with wanting for example folder/folder.jpg or folder/cover.jpg as the icon for a folder containing a media collection.

When I search for that myself I only hit on the outdated https://github.com/flozz/cover-thumbnailer which has been dead since basically 2011. I would not recommend trying to install that but would recommend using it as a starting point if you were to code something up yourself. Which you may need to; it seems KDE may be an exception but am not finding a current cover thumbnailer for any current file manager as used by Mint.
rahulkundu4u

Re: Solution for Folder Icon

Post by rahulkundu4u »

I have tried the above solution unfortunately, it does not work with nemo.

We can change the directory icon from properties manually one by one. After little bit search, I came to know that custom-icon info is kept as directory meta-data (gio info /directory-path). If I get any solution that will load this meta-data in bulk from a config file that will resolve my problem. In this way, I have to create the config once and then I can load at any time.
User avatar
smurphos
Level 18
Level 18
Posts: 8498
Joined: Fri Sep 05, 2014 12:18 am
Location: Irish Brit in Portugal
Contact:

Re: Solution for Folder Icon

Post by smurphos »

rahulkundu4u wrote: Sun Jan 20, 2019 2:25 pm What I want is to keep the folder icon inside each folder and the folder should automatically apply the icon. In this way, the folder icon will be kept intact even I format the os or copy the folders to an external HDD.
Here is a little bash script that should work in 19.x with nemo to set a custom icon programmatically to a selection of folders. My testing has been limited. :wink:

Prerequisite - each folder that you want to have a custom icon should hold the icon you want to apply but they should all have the same name e.g thisfoldericon.png.

Replace "/path/of/interest/" with the directory you actually want to search - e.g "/media/data/" or whatever.

Code: Select all

#!/bin/bash
for F in $(find "/path/of/interest/" -type d); do
  if [[ -f "$F"/thisfoldericon.png ]]; then
    echo "Applying "$F"/thisfoldericon.png as custom icon to "$F""
    gio set "$F" metadata::custom-icon file://"$F"/thisfoldericon.png
  fi
done
For custom Nemo actions, useful scripts for the Cinnamon desktop, and Cinnamox themes visit my Github pages.
rahulkundu4u

Re: Solution for Folder Icon

Post by rahulkundu4u »

Wow, this just works. Think you very much @ smurphos

I really like Linux Mint as it is and do not want to change the default things e.g. file browser because of stability. I believe this is a useful feature for many regular desktop users and this small utility should be included in Linux Mint by default.
rahulkundu4u

Re: [SOLVED] - Solution for Folder Icon

Post by rahulkundu4u »

I found one minor issue. The solution does not work where the directory name contains space. I have solved it in the following way.

Code: Select all

#!/bin/bash
OIFS="$IFS";IFS=$'\n';for F in $(find "/path/of/interest/" -type d); do
  if [[ -f "$F"/thisfoldericon.png ]]; then
    echo "Applying "$F"/thisfoldericon.png as custom icon to "$F""
    gio set "$F" metadata::custom-icon file://"$F"/thisfoldericon.png
  fi
done;IFS="$OIFS"
User avatar
smurphos
Level 18
Level 18
Posts: 8498
Joined: Fri Sep 05, 2014 12:18 am
Location: Irish Brit in Portugal
Contact:

Re: [SOLVED] - Solution for Folder Icon

Post by smurphos »

Thanks for that and the fix. I wonder if there is another workaround? This has got me thinking about methods to backup and restore other metadata (emblems etc)......
For custom Nemo actions, useful scripts for the Cinnamon desktop, and Cinnamox themes visit my Github pages.
rene
Level 20
Level 20
Posts: 12212
Joined: Sun Mar 27, 2016 6:58 pm

Re: [SOLVED] - Solution for Folder Icon

Post by rene »

smurphos wrote: Thu Jan 24, 2019 3:07 am I wonder if there is another workaround?
Generic would be to let find execute the loop body itself, i.e.,

Code: Select all

find "/path/of/interest" -type d -exec /bin/sh -c '[ -r "{}"/thisfoldericon.png ] && echo "..." && echo gio set "{}" ...' \;
but what I find to be a lot nicer is zero-terminating and piping into a while read loop:

Code: Select all

find /path/of/interest/ -type d -print0 | while read -d $'\0' F; do
  if [ -r "$F"/thisfoldericon.png ]; then
    echo Applying "$F"/thisfoldericon.png as custom icon to "$F"
    gio set "$F" metadata::custom-icon file://"$F"/thisfoldericon.png
  fi
done
I'd by the way consider naming the icon "folder.png" (and/or scan for a few possible names such as folder.png, folder.jpg, cover.png, cover.jpg, ...) for compatibility with Windows.
Locked

Return to “Cinnamon”