V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
stx0821
V2EX  ›  Windows

有大量包含图片的文件夹,如何批量选中每个文件夹中的第一张图片

  •  
  •   stx0821 · 170 天前 · 742 次点击
    这是一个创建于 170 天前的主题,其中的信息可能已经有所发展或是发生改变。

    选中之后复制出来做为预览图片,在 windows 系统下,有这种操作吗

    5 条回复    2023-11-15 16:44:00 +08:00
    proxytoworld
        1
    proxytoworld  
       170 天前
    只能用脚本吧
    lisxour
        2
    lisxour  
       170 天前
    资源管理器没有这种操作,只有代码才能实现
    tool2d
        3
    tool2d  
       170 天前   ❤️ 1
    问了一下 gpt: "写一个 bat, 遍历目录,列出每个目录下的第一个图片文件。"

    直接帮我了写一个。
    franswish
        4
    franswish  
       169 天前 via Android
    如何定义“第一个”?首字母排序?创建时间排序?
    byzod
        5
    byzod  
       167 天前
    正好之前写了个蛋疼的“根据 id 分组并统计作品数量阈值挑选一张每个艺术家最新的作品”
    你改改就能用了

    ```
    #Requires Autohotkey v2.0+
    #SingleInstance Force

    SrcFolder := "Q:\Doc\Pic\#Pixiv"
    DestFolder := "Q:\Doc\Pic\#Pixiv\#Index"
    idRegex := "^(\d+)\s+-\s+.+$" ; id as group 1
    Threshold := 20

    IdList := Map()
    Loop Files, SrcFolder . "\*.*", "F"
    {
    ; 处理文件列表
    fileName := Trim(A_LoopFileName)
    matchArray := {}
    match := RegExMatch(fileName, idRegex, &matchArray)
    if (match) {
    id := matchArray[1]
    if (!IdList.Has(id)) {
    IdList.Set(id, IdInfo(id, 1, A_LoopFilePath))
    } else {
    IdList.Get(id).count += 1
    IdList.Get(id).latestFile := A_LoopFilePath
    IdList.Get(id).latestFileName := fileName
    }
    }
    }

    ; 阈值过滤
    IdListPicked := Map()
    for id, info in IdList
    {
    if (info.count >= Threshold)
    {
    IdListPicked.Set(id, info)
    }
    }

    ; 移动
    debug_pickArtStr := "" ;debug
    if (IdListPicked.Count > 0){
    try FileDelete(DestFolder . "\*.*")
    try DirCreate(DestFolder)
    for id, info in IdListPicked
    {
    if(FileExist(info.latestFile)) {
    FileCopy(info.latestFile, DestFolder)
    ; debug_pickArtStr .= info.count . ": " . info.latestFileName . "`n" ;debug
    }
    }
    }

    ; 输出到文件
    ; 输出处理完成的消息
    MsgBox("文件处理完成`n`n"
    "作品数量阈值" . Threshold . "`n 共" . IdListPicked.Count . "艺术家符合"
    )
    ; MsgBox(debug_pickArtStr) ;debug


    Class IdInfo {
    id := 0
    count := 0
    latestFile := ""
    __New(id:=0, count:=0, latestFile:="", latestFileName:="") {
    this.id := id
    this.count := count
    this.latestFile := latestFile
    this.latestFileName := latestFileName
    }
    }

    ExitApp

    ```
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2310 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 06:55 · PVG 14:55 · LAX 23:55 · JFK 02:55
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.