Command Palette

Search for a command to run...

UnylyUnyly
Back to skills

Python异步解压Zip和Tar文件

FreeNo executable scriptsNot checked

遍历指定目录查找Zip和Tar.gz文件,使用asyncio的run_in_executor进行异步解压,并实现不覆盖同名文件的逻辑。

ECNU-ICALKby ECNU-ICALK★ 623 GitHub stars

About this skill

Python异步解压Zip和Tar文件

遍历指定目录查找Zip和Tar.gz文件,使用asyncio的run_in_executor进行异步解压,并实现不覆盖同名文件的逻辑。

Prompt

Role & Objective

你是一个Python异步编程专家。你的任务是编写代码,遍历指定目录,查找所有的.zip和.tar.gz文件,并使用异步方式解压它们。

Operational Rules & Constraints

  1. 异步执行:由于zipfile和tarfile是同步阻塞库,必须使用asyncio.get_running_loop().run_in_executor将解压操作放入线程池中执行,以避免阻塞事件循环。
  2. 目录遍历:使用os.walk遍历输入目录。
  3. 文件过滤:仅处理以.zip或.tar.gz结尾的文件。
  4. 解压路径构建:根据源文件所在的文件夹名称(os.path.basename(dirpath))构建解压目标路径,通常格式为os.path.join("tmp", folder_basename)。
  5. 不覆盖同名文件:在解压前检查目标路径下文件是否存在。如果存在,则跳过该文件的解压,不进行覆盖操作。
  6. 并发控制:使用asyncio.create_task创建任务,并使用await asyncio.gather(*tasks)等待所有任务完成。

Anti-Patterns

  • 不要直接在async函数中使用zipfile.ZipFile或tarfile.open而不通过run_in_executor,这会阻塞事件循环。
  • 不要使用async with配合zipfile或tarfile,因为它们不支持异步上下文管理器。
  • 不要在解压时覆盖已存在的同名文件。

Triggers

  • python 异步解压 zip
  • asyncio tarfile 解压
  • python 遍历目录解压压缩包
  • 异步文件解压不覆盖

Install Python异步解压Zip和Tar文件 in Claude Code & Claude Desktop

Sign up to install this skill

Create a free account to reveal the install command and save the skill to your library.

  • Reveal the one-line install command
  • Save skills to your synced library
  • Get notified when skills update
Sign up freeI already have an account

Allowed tools

Tools this skill is permitted to call.

No restriction — this skill can use any tool.

FAQ

What does the Python异步解压Zip和Tar文件 skill do?

遍历指定目录查找Zip和Tar.gz文件,使用asyncio的run_in_executor进行异步解压,并实现不覆盖同名文件的逻辑。

How do I install the Python异步解压Zip和Tar文件 skill?

Copy the skill folder into ~/.claude/skills (the Claude Code tab above does this in one command), or install it as a plugin.

Does the Python异步解压Zip和Tar文件 skill run scripts?

No, this skill is instructions only (SKILL.md) with no executable scripts.

Related skills

Compare Python异步解压Zip和Tar文件 with