Folder-Color saved files/folder

Hello there,
I hope you're doing well! I'm wondering if you could help me out—where might I find the 'folder-color' configuration files? I’d love to save them for my next Zorin installation so that I can keep all my folder ticks and colors just the way I like them.
Thank you so much for your assistance!

In a terminal, run:

gio info <name_of_file>

This will return all sorts of useful metadata about the file, including it's icon. You can narrow it down to get this with:

gio info <name_of_file> | awk '/custom-icon-name/ { print $2 }'

To change that:

gio set <name_of_file> metadata::custom-icon-name <folder_color>

Where <folder_color_color> is one of the available colors, which you can extract from the previous command. To apply it:

gio set <name_of_file> metadata::custom-icon-name <folder_color>

For example:

gio set /home/zenzen/Music metadata::custom-icon-name folder_color_red
1 Like

I really appreciate it; with this approach, I'm able to locate all the details regarding a file or folder. However, I need to gather specific metadata about folders and save it, and since there are over 500 folders, I can't echo them individually.

Is this any help?:

"Export Folder Colors to Linux Batch

To export folder color configurations as a batch file in Linux, you’ll need to:

  1. Backup the current LS_COLORS variable: Run the command export LS_COLORS_BACKUP="$LS_COLORS" to save the current value of LS_COLORS into a temporary variable.
  2. Extract the relevant configuration: Identify the specific lines in your ~/.bashrc or equivalent configuration file that set the folder color configurations (e.g., di=0;34: for directories in blue).
  3. Create a batch file: Use a text editor (e.g., nano, vim) to create a new file, e.g., folder_colors.sh. Add the following lines:
#!/bin/bash

# Set the LS_COLORS variable
export LS_COLORS=$LS_COLORS_BACKUP
# Add the folder color configurations
export LS_COLORS=$LS_COLORS:'di=0;34:'  # Blue color for directories
export LS_COLORS=$LS_COLORS:'fi=0;35:'  # Magenta color for files
  1. Make the batch file executable: Run the command chmod +x folder_colors.sh to make the file executable.
  2. Test the batch file: Run the batch file by executing ./folder_colors.sh. Verify that the folder colors are applied correctly.
  3. Package the batch file: To make it easy to apply the folder color configurations to a new Linux installation, create a tarball or ZIP archive containing the folder_colors.sh file and any other necessary files (e.g., ~/.bashrc).

Example tarball contents:

  • folder_colors.sh
  • ~/.bashrc (or equivalent configuration file)

Applying the batch file to a new install:

  1. Extract the tarball or ZIP archive to the new Linux installation’s home directory (e.g., ~/).
  2. Run the batch file by executing ./folder_colors.sh.
  3. Verify that the folder colors are applied correctly.

Note: This approach assumes you’re using Bash as your shell. If you’re using a different shell (e.g., Zsh), you may need to modify the batch file accordingly. Additionally, some Linux distributions might have different configuration file locations or formats, so be sure to adapt the batch file accordingly."

1 Like

As I've been dabbling with Perl lately, and this is inherently a text parsing exercise, I'll provide a solution using Perl. Don't worry, Perl comes installed by default in just about every distribution, and is even more portable and faster than Python:

To generate a report of all the folders that have custom colors, you can run this script. Create a new text file with whatever name you like, with the following contents — make sure to update the $filename and $start variables with your own desired locations and filename for this report; I'd recommend using absolute values for the path i.e, /home/zenzen/ as opposed to ./zenzen:

#!/bin/perl

use File::Find;

my $filename = '/home/zenzen/folders_with_colors.csv';
my $start = '/home/zenzen/';

open(FH, '>', $filename) or die $!;

sub wanted {
	if (! -d) { return };
	my @metadata = qx`gio info $File::Find::name 2>/dev/null`;
	foreach (@metadata) {
		if (/custom-icon-name:\s*([a-z_\-]*)\b$/i) {
			print FH "$File::Find::name,$1\n";
		}
	}
};

find(\&wanted,  $start);

This will produce a CSV (comma-separated values) file with the names of the folders and their associated custom color. To restore it, you can again run another script:

#!/bin/perl

my $filename = '/home/zenzen/folders_with_colors.csv';
open(FH, '<', $filename) or die $!;

while (<FH>) {
	my ($filename,$color) = split /,/, $_;
	qx`gio set $filename metadata::custom-icon-name $color 2>/dev/null`;
}
2 Likes

I appreciate your help; this is effective, but what is the method to search through all the files and directories on the system?

In Perl, the function find is provided by the built-in module File::Find. It's effectively equivalent to the find command that you can run directly on the terminal. How it works is you provide a starting point and it will search for whatever criteria was given.

For example, running this on the terminal will find all directories (folders) in the user's home folder.

find $HOME -type d

In Perl, the equivalent code may look something like this:

sub wanted {
    say if -d;
}

find(\&wanted, $ENV{HOME});

Notice, however, that you need to define a function separately which is more verbose, but with the huge advantage of being far more expressive and flexible.

1 Like