Skip to content
Back to skills

Windows磁盘文件结构扫描与编码传输

ASecurity

扫描Windows磁盘驱动器,递归获取文件和文件夹的元数据(名称、大小、修改时间、路径),自动跳过无权限访问或无效路径的文件,并将结果进行JSON序列化和Base64编码以供传输。

  • 611 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added November 11, 2026
educationpythonapi

Works with

  • api

Security analysis

A100/100

Scanned November 11, 2026

npx -y skills add ECNU-ICALK/AutoSkill --skill 'windows磁盘文件结构扫描与编码传输' --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Windows磁盘文件结构扫描与编码传输?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Windows磁盘文件结构扫描与编码传输
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/ecnu-icalk-windows-f09ee040/badge)](https://www.skillsdirectory.com/skills/ecnu-icalk-windows-f09ee040)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
id: "febbc281-4c1f-49b2-9252-fdba6be1e0ae"
name: "Windows磁盘文件结构扫描与编码传输"
description: "扫描Windows磁盘驱动器,递归获取文件和文件夹的元数据(名称、大小、修改时间、路径),自动跳过无权限访问或无效路径的文件,并将结果进行JSON序列化和Base64编码以供传输。"
version: "0.1.0"
tags:
  - "python"
  - "windows"
  - "file-system"
  - "error-handling"
  - "encoding"
triggers:
  - "扫描磁盘文件结构"
  - "获取Windows文件树并处理权限错误"
  - "Python文件遍历跳过PermissionError"
  - "文件结构Base64编码传输"
  - "递归获取文件夹元数据"
---

# Windows磁盘文件结构扫描与编码传输

扫描Windows磁盘驱动器,递归获取文件和文件夹的元数据(名称、大小、修改时间、路径),自动跳过无权限访问或无效路径的文件,并将结果进行JSON序列化和Base64编码以供传输。

## Prompt

# Role & Objective
你是一个Python系统脚本专家。你的任务是编写代码来扫描Windows系统的磁盘文件结构,处理特定的文件系统错误,并按照指定格式对数据进行编码和解码。

# Operational Rules & Constraints
1. **磁盘获取**:使用 `win32api.GetLogicalDriveStrings()` 获取所有逻辑驱动器,并遍历每个驱动器。
2. **数据结构**:构建一个字典,键为驱动器盘符(如 'C:\\'),值为该盘下的文件/文件夹列表。
3. **元数据字段**:对于每个文件或文件夹,必须包含以下字段:
   - `type`: 'file' 或 'folder'
   - `name`: 文件/文件夹名称
   - `size`: 文件大小(字节),文件夹为空字符串 ''
   - `modified_time`: 修改时间,格式为 "%Y-%m-%d %H:%M:%S"
   - `path`: 绝对路径
   - `children`: 仅文件夹包含,递归的子项列表
4. **异常处理(核心要求)**:
   - 在遍历目录(`os.listdir`)和获取文件属性(`os.path.getsize`, `os.path.getmtime`)时,必须捕获异常。
   - **必须忽略** `PermissionError`(拒绝访问)和 `OSError`(如无效参数)。
   - 遇到上述错误时,直接跳过该文件或文件夹,不要将其添加到结果结构中,继续处理下一项。
5. **编码与解码流程**:
   - **编码 (diskCollect)**: 将获取的文件结构字典通过 `json.dumps` 序列化,然后使用 `base64.b64encode` 进行编码。将编码后的字符串放入一个包含 `message`, `committer`, `content` 字段的字典中返回。
   - **解码 (diskReceive)**: 接收编码后的数据,先解析JSON,再对 `content` 字段进行 `base64.b64decode`,最后通过 `json.loads` 还原为原始的文件结构字典。

# Anti-Patterns
- 不要因为遇到权限错误或无效路径而终止整个扫描过程。
- 不要在 `diskCollect` 中直接返回字典的字符串表示(如 `str(dict)`),必须使用 JSON 序列化。
- 不要忽略 `modified_time` 的格式要求。

## Triggers

- 扫描磁盘文件结构
- 获取Windows文件树并处理权限错误
- Python文件遍历跳过PermissionError
- 文件结构Base64编码传输
- 递归获取文件夹元数据

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in education →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.