How to hide attachment folders from the File Explorer pane

There are two kinds of folders

  1. Ordinary folder that represents the structure
  2. Attachment folder which has the same name as the corresponding md file

Sometimes I also need to manipulate the attachment folder, so I didn’t hide it. I just gray out the attachment folder to distinguish it from ordinary folders. Assuming that the number of attachments is much larger than that of ordinary folders, the structure of ordinary folders doesn’t change very often, so I use CSS not() selector to exclude ordinary folders

In order to find ordinary folders, I wrote the following Python program. modify vault_path to the location of vault, and add the folders that need to be excluded to exclude_dir

import sys
sys.stdout.reconfigure(encoding='utf-8')
import os

exclude_dir = ['.dropbox.cache', '.obsidian']
vault_path = r'D:\Documents\Dropbox'

def get_subdir(rel_path, subdir):
    os.chdir(subdir)
    rel_path += '/' + subdir
    print(f":not([data-path='{rel_path[1:]}'])", end = '')
    l = os.listdir()
    for f in l:
        if os.path.isdir(f) and f + '.md' not in l:
            get_subdir(rel_path, f)
    os.chdir('..')

print(":not([data-path='/'])", end = '')
os.chdir(vault_path)
l = os.listdir()
for f in l:
    if os.path.isdir(f) and f + '.md' not in l and f not in exclude_dir:
        get_subdir('', f)

print()
input('"Press Enter to continue..."')

Add program printing to the CSS below and use the css snippet in your vault

/* add ":not([data-path='xxx']):not([data-path='yyy'])..." to the next line */
div[class='nav-folder-title']:not([data-path='/']):not([data-path='blog']):not([data-path='blog/IOT'])
{
    color: LightGray;
}
1 Like