---
name: recycle-bin-inspector-yashu
description: 查看 Windows 回收站里有哪些文件、有多少个。默认只列出最多 6 个文件名，用户要求看全部时列出所有回收站文件名。当用户问"回收站里有几个文件""回收站里有什么""回收站空了没""回收站还有多少东西""看下回收站""我删的文件能恢复吗""清空回收站会怎样"，或需要确认某文件是否还在回收站、判断磁盘空间是否被回收站占用时使用。也用于核对资源管理器回收站显示的数量是否准确、排查"元数据还在但内容丢失"的幽灵残留条目。
disable-model-invocation: false
title: recycle-bin-inspector-yashu
canonical_url: https://skilld.dev/gh/steelan9199/wechat-publisher/recycle-bin-inspector-yashu
last_updated: 2026-10-07T07:20:50.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> Supporting files, fetch one when the Skill refers to it: [scripts/list_recycle_bin.py](https://skilld.dev/api/skills-raw/steelan9199/wechat-publisher/recycle-bin-inspector-yashu/scripts/list_recycle_bin.py).
>
> If the user asked to install this Skill, run `npx skilld install steelan9199/wechat-publisher/recycle-bin-inspector-yashu`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/recycle-bin-inspector-yashu`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/steelan9199/wechat-publisher/recycle-bin-inspector-yashu) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/recycle-bin-inspector-yashu`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/recycle-bin-inspector-yashu --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/recycle-bin-inspector-yashu --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# Windows 回收站查看

统计并列出 Windows 回收站的文件。**口径与资源管理器 GUI 完全一致**。

脚本位置：`scripts/list_recycle_bin.py`（纯标准库，无需 pip 安装）

解释器路径（本机）：
`D:\software\uv\python\cpython-3.14.7-windows-x86_64-none\python.exe`

## 一、快速开始

```bash
PY="D:/software/uv/python/cpython-3.14.7-windows-x86_64-none/python.exe"
S="C:/Users/Administrator/.workbuddy/skills/recycle-bin-inspector-yashu/scripts/list_recycle_bin.py"

"$PY" "$S"                 # 默认：总数 + 最多 6 个文件名
"$PY" "$S" --all           # 打印所有回收站文件名
"$PY" "$S" --drive D       # 只看 D 盘
"$PY" "$S" --limit 20      # 自定义上限
"$PY" "$S" --json          # 输出 JSON
```

**结果一律写入文件**（默认当前目录 `recycle_bin_report.txt`，可用 `--out` 改），
然后用 Read 读那个文件。**不要只依赖 stdout 回显** —— 本机 stdout 常常不回传。

> 提示：报告里如果含非 ASCII 字符，Read 工具可能判为二进制文件而拒绝打开。
> 此时用 Python 读回：`python -c "import sys;sys.stdout.reconfigure(encoding='utf-8',errors='replace');print(open(r'路径',encoding='utf-8').read())"`

## 二、行为约定（重要）

**默认只显示 6 个。** 用户明确要求"全部""所有""都列出来""看完整清单"时，加 `--all` 输出全部条目，并在回复中说明总数。

不要自作主张一次性打印几十条 —— 回收站动辄上百项，刷屏且无用。先给 6 条 + 总数，让用户决定要不要展开。

## 三、计数口径（关键，务必理解）

回收站里存在**两套数字**，混淆会得出完全错误的结论：

| 概念 | 含义 | 是否显示在 GUI |
|---|---|---|
| **有效条目** | `$I` 元数据 + `$R` 内容文件**双全** | ✅ 显示，可还原 |
| **幽灵残留** | 只有 `$I` 元数据，`$R` 内容已丢失 | ❌ 不显示，还原会失败 |

**本技能只统计「有效条目」**，因此数字 = 资源管理器显示的数字。幽灵残留单独报一个计数，不混入总数。

实测参考：本机 C 盘有 29 条元数据，但有效条目 **0** 个 —— GUI 同样显示 0。
若按元数据条数汇报，会得出"C 盘有 29 个文件在回收站"的错误结论。

**不要用「元数据条数」回答用户问的"回收站里有几个文件"。**

## 四、回收站是按盘隔离的

不是全局一个目录，而是**每个盘各有一个** `X:\$Recycle.BIN`：

- 资源管理器里的「回收站」是所有盘的**聚合视图**，数据各存各的，从不合并
- 从哪个盘删文件，就进那个盘的回收站
- 脚本默认扫描所有就绪盘符（C: D: E: F: ...），逐盘统计
- 某盘没有 `$Recycle.BIN` 目录 = 从未在该盘删过文件，属正常

## 五、输出结构

```
有效条目总数 / 占用空间合计 / 不可恢复残留条数
— 各盘分布 —        每盘项数 + 体积 + GUI 报告数
— 条目清单 —        序号、删除时间、原始大小、原始完整路径
— 交叉校验 —        脚本数字 vs Shell API 数字
```

脚本会用 `SHQueryRecycleBinW` 取 Shell 权威数字做交叉校验，不一致会打 ⚠ 警告。
**这个校验信号很重要** —— 若出现 ⚠，说明元数据解析与系统视图脱节，数字不可信，应如实告知用户。

## 六、技术要点

- **纯标准库 + ctypes**，不调 COM、不用 PowerShell。原因：COM 在本机被安全策略拦截；而 PowerShell 每次运行都会向回收站投递 `__PSScriptPolicyTest_*.ps1` 临时脚本，污染计数。
- 只统计 `S-1-5-21*` 开头的 SID 目录（当前用户），跳过 `S-1-5-18`（系统，仅 desktop.ini）。
- `$I` 文件布局：8 字节版本号 + 8 字节原大小 + 8 字节删除时间(FILETIME) + UTF-16LE 原始路径。
- **易踩的坑**：`os.path.join("D:", "$Recycle.BIN")` 得到 `D:$Recycle.BIN`（缺反斜杠），因为 `"D:"` 被当作驱动器相对路径。必须显式补 `\`。已修复，改动扫描逻辑时勿回退。
- 文件名显示**原始完整路径**而非纯文件名 —— 回收站里重名极多，只给文件名无法区分。

## 七、注意事项

- 本技能**只读不删**。清空回收站、恢复文件都是破坏性操作，必须由用户明确发起，并先用本技能列出待处理清单供确认。
- 大文件（数百 MB）被删后，若只剩元数据、内容已丢失，**无法恢复**。发现此类条目应主动提示用户，避免用户误以为"还在回收站里能捞回来"而放弃其他找回途径。
