【文件夹】修改文件夹备注字段进行排序 --37

【文件夹】修改文件夹备注字段进行排序 --37


--作者:李菠萝的多样空间

--创建时间:2026-09-13

--需求描述:博文的博文文件夹命名都是尾部加数字,若使用自带的名称排序则会很乱,因此琢磨了这个用备注字段排序。

--学习对象说明和链接:手动方式成功复现。关于自动化的实现,是用的脚本实现,简化了操作,只需要把脚本放入需要修改备注的文件夹的下级,用PowerShell打开即可启动修改界面,输入要修改的内容即可。

windows系统下,如何给文件夹添加备注?文件夹查看备注-腾讯云开发者社区-腾讯云


打开文件夹的【备注】字段的显示

右键文件夹的字段选项卡,选择其他。找到【备注】并勾选,点击【上移】按钮可将其默认位置提前,确认完成即可。

修改【备注】字段的两种方式

方式1:手动激活与配置

  1. 在需要更改备注的文件夹的下一级,右键后选择【属性】,在【自定义】点击一次【还原默认图标】点击确认。

  2. 右键自动生成的ini配置文件,添加以下代码并保存:

    [.ShellClassInfo]
    InfoTip=##3
    

    参数InfoTip后填写备注内容(中文字符会乱码)

  3. 返回上一级刷新,等待一分钟即可正常显示


方式2:Shell脚本自动化实现

核心逻辑

锁定脚本自身目录 → 弹窗收备注 → 写/改 desktop.ini 的 InfoTip → 设系统/隐藏属性 → 通知 Explorer 刷新;全程异常弹窗不崩。

核心代码(大模型编写)

## 博客园:李菠萝的多样空间,2026年9月11日

try {
    $targetFolder = $PSScriptRoot
    if (-not (Test-Path $targetFolder)) {
        throw "Target folder not found: $targetFolder"
    }

    Add-Type -AssemblyName Microsoft.VisualBasic -ErrorAction SilentlyContinue
    $note = [Microsoft.VisualBasic.Interaction]::InputBox(
        "Enter the InfoTip (comment) for THIS folder (where the script lives):", "Set Folder InfoTip", "")

    if ([string]::IsNullOrWhiteSpace($note)) { exit 0 }

    $iniPath = Join-Path $targetFolder "desktop.ini"
    if (-not (Test-Path $iniPath)) {
        $template = "[.ShellClassInfo]`r`nInfoTip=$note`r`n"
        Set-Content -Path $iniPath -Value $template -Encoding Default -Force
    } else {
        $content = Get-Content -Path $iniPath -Raw
        if ($content -notmatch '\[\.ShellClassInfo\]') { $content = "[.ShellClassInfo]`r`n" + $content }
        if ($content -match 'InfoTip=') {
            $content = $content -replace 'InfoTip=.*', "InfoTip=$note"
        } else {
            $content = $content -replace '(\[\.ShellClassInfo\]\r?\n)', "`$1InfoTip=$note`r`n"
        }
        Set-Content -Path $iniPath -Value $content -Encoding Default -Force
    }

    attrib +h +s "$iniPath" | Out-Null
    attrib +s "$targetFolder" | Out-Null

    try {
        Add-Type @"
using System;
using System.Runtime.InteropServices;
public class ShellNotify {
    [DllImport("shell32.dll", CharSet=CharSet.Unicode)]
    public static extern void SHChangeNotify(int wEventId, int uFlags, string dwItem1, IntPtr dwItem2);
}
"@
        [ShellNotify]::SHChangeNotify(0x00002000, 0x0005, $targetFolder, [IntPtr]::Zero)
    } catch {
        [Microsoft.VisualBasic.Interaction]::MsgBox("InfoTip written, but auto-refresh failed. Press F5 in Explorer to see it.", "OKOnly,Exclamation", "Note")
    }

    [Microsoft.VisualBasic.Interaction]::MsgBox("InfoTip set for this folder:`n$targetFolder`n`nValue: $note", "OKOnly,Information", "Done")
}
catch {
    [Microsoft.VisualBasic.Interaction]::MsgBox("Error: $_", "OKOnly,Critical", "Error")
}



实现效果


转载请注明作者与来源,禁止商用。

不构成任何买卖建议,仅个人学习使用。

使用了 AI 辅助创作(语句润色,结构排版等)

END

posted @ 2026-09-13 23:08  李菠萝的多样空间  阅读(12)  评论(0)    收藏  举报