1

I have hundreds of folders of images on my HDD, and with very few exceptions they each have a cover image that I want to use as their respective folder thumbnails, or at least a memorable first image. Unfortunately, Windows 10 defaults to using two random images in the folder as the thumbnail, and I have to manually select the first image as the thumbnail in the folder properties every singe time. Recently Windows automatically wiped the thumbnail cache, and I really don't want to manually reset the thumbnails on these folders.

Is there a way to automate going into a folder's properties, the customize tab, folder pictures, and selecting the first item in the folder every time? Or would I need a hypothetical "Folder.properties.setFolderPicture()" that Windows doesn't have for security reasons? Python is the only language I have any experience with, but if I need another language to do this I'm willing to try it.

2 Answers2

1

I don't have reputation to comment, so I pile up my answer here. I feel you are better of using folder icons for this purpose, since nowhere on the Internet could I find a way to programmatically set folder pictures, but I'm sure its some registry trickery.

import os
from PIL import Image
from configparser import ConfigParser

MAX_SIZE = 256, 256

image = Image.open(name_dot_format)
image.thumbnail(MAX_SIZE)
image.save(name_dot_ico)

ini = ConfigParser()
ini['.ShellClassInfo'] = {'IconResource': f'{name_dot_ico},0'}
try:
    with open('desktop.ini', 'w') as desktop_ini:
        ini.write(desktop_ini)
    os.system("attrib +s +h desktop.ini")
    os.system("attrib +r .")
except PermissionError:
    # Don't mess up the already existing desktop.ini
    os.system("attrib -r .")
    os.system("attrib -s -h desktop.ini")
    with open('desktop.ini', 'a') as desktop_ini:
        ini.write(desktop_ini)
    os.system("attrib +s +h desktop.ini")
    os.system("attrib +r .")
demberto
  • 489
  • 5
  • 15
0

Take a look over here if it helps you.

win32api / pywin32

Community
  • 1
  • 1
Diggy.
  • 6,744
  • 3
  • 19
  • 38
  • 1
    That looks promising, but also confusing. The top answer is a block of code with no clear purpose to me. It's also a question about icons, which is similar to but slightly different from thumbnails, which use an existing high res image from within the folder, rather than a .ico file. I don't know how Windows handles icons, if it's a good idea to set up custom icons for hundreds of tiny image folders, compared to the thumbnail feature that seems to be intended for this sort of thing. I'll look into the pywin32 link now, will edit when I'm done. – FireHawkDelta May 11 '20 at 23:16
  • @FireHawkDelta Unfortunately the module they're using is a bit low-level, but that's not to say it hasn't been [documented](http://timgolden.me.uk/pywin32-docs/contents.html). Additionally, if you'd rather do this via command prompt, I can recommend using something such as [subprocess.Popen](https://stackoverflow.com/questions/12605498/how-to-use-subprocess-popen-python) for changing the icons via [Command line](https://stackoverflow.com/questions/37095448/how-to-change-existing-folders-icon-via-command-line-windows-10). – Diggy. May 11 '20 at 23:21
  • 1
    I looked for a way to change a folder's properties in the win32api documentation, found nothing in the win32file page and have no idea where else to look. GetFileAttributes returns a number for folders, so I guess that's literally just saying "this is a folder". – FireHawkDelta May 12 '20 at 00:17