转跳到内容

怎么把批量把文件夹第一张图片在文件夹上显示


推荐贴

如果你会python的话 希望下面这段我自用的代码能帮到你。

这是我用来给黄油改文件夹封面用的

from PIL import Image
import os
import re


def make_ico_file(src_image_file, dist_ico_file, size_list=None):
    """
    :param src_image_file:
    :param dist_ico_file:
    :return:
    """
    default_size_list = [
        (256, 256),
        (128, 128),
        (64, 64),
        (48, 48),
        (32, 32),
        (24, 24),
        (16, 16)
    ]
    size_list = size_list or default_size_list
    image = Image.open(src_image_file)
    image = image.convert('RGBA')
    image.thumbnail([256, 256])
    width, height = image.size
    new_image = Image.new('RGBA', (256, 256), (0, 0, 0, 0))
    if width == 256:
        upper = (256 - height) // 2
        new_image.paste(image, (0, upper))
    elif height == 256:
        left = (256 - width) // 2
        new_image.paste(image, (left, 0))
    else:
        print('error')
    # image_cropped = image.crop((0, 0, 256, 256))

    # new_image.save(r'.\test\re.png')
    new_image.save(dist_ico_file, sizes=size_list)


def listdirs(folder):
    return [
        d for d in (os.path.join(folder, d1) for d1 in os.listdir(folder))
        if os.path.isdir(d)
    ]


def listfiles(folder):
    return [
        d for d in (os.path.join(folder, d1) for d1 in os.listdir(folder))
        if os.path.isfile(d)
    ]


def find_getchu_cover(folder):
    pattern = r'c[0-9]+package\.jpg'
    f = listfiles(folder)

    for file in f:
        result = re.search(pattern, file)
        if result is not None:
            return result.group()


if __name__ == '__main__':
    base_dir = r'E:\EroEroEro'

    dirs = listdirs(base_dir)
    cover_path = ''

    for name in dirs:
        if os.path.exists(name + "\\cover.jpg"):
            cover_path = name + "\\cover.jpg"
        elif find_getchu_cover(name) is not None:
            cover_path = name + '\\' + find_getchu_cover(name)
        else:
            print("Cover Not Found")
            break
        make_ico_file(src_image_file=cover_path,
                      dist_ico_file=name + '\\fic.ico')

        desktop_ini = ["[.ShellClassInfo]\n\r", "IconResource=fic.ico,0\n\r", 'FolderType=Pictures']
        with open(name + '\\desktop.ini', 'w') as f:
            f.writelines(desktop_ini)
            f.close()
        print(name)
        os.system('attrib +s +h ' + '"' + name + '"' + '\\desktop.ini')
        os.system('attrib +r ' + '"' + name + '"')

 

链接到点评
4 小时前,eroko说道:

如果你会python的话 希望下面这段我自用的代码能帮到你。

这是我用来给黄油改文件夹封面用的

 

不会编程:1529987897_SSA(2):

2 小时前,古澜心殇说道:

简单一点的话

右键菜单选属性就能改:SS02:1470635447_QQ20230917213310.png.80e669e4d304738274976cd001e4f1a8.png

我就是用这个法子的,但是太慢了而且太麻烦了:2098100325_SSA(4):

vicehade抓到了盗链的熊孩子,受到了环姐的嘉奖8节操。

链接到点评
游客
此主题已关闭。
×
×
  • 新建...

重要消息

为使您更好地使用该站点,请仔细阅读以下内容: 使用条款