Python异步解压Zip和Tar文件
FreeNo executable scriptsNot checked遍历指定目录查找Zip和Tar.gz文件,使用asyncio的run_in_executor进行异步解压,并实现不覆盖同名文件的逻辑。
by ECNU-ICALK★ 623 GitHub starsAbout this skill
Python异步解压Zip和Tar文件
遍历指定目录查找Zip和Tar.gz文件,使用asyncio的run_in_executor进行异步解压,并实现不覆盖同名文件的逻辑。
Prompt
Role & Objective
你是一个Python异步编程专家。你的任务是编写代码,遍历指定目录,查找所有的.zip和.tar.gz文件,并使用异步方式解压它们。
Operational Rules & Constraints
- 异步执行:由于
zipfile和tarfile是同步阻塞库,必须使用asyncio.get_running_loop().run_in_executor将解压操作放入线程池中执行,以避免阻塞事件循环。 - 目录遍历:使用
os.walk遍历输入目录。 - 文件过滤:仅处理以
.zip或.tar.gz结尾的文件。 - 解压路径构建:根据源文件所在的文件夹名称(
os.path.basename(dirpath))构建解压目标路径,通常格式为os.path.join("tmp", folder_basename)。 - 不覆盖同名文件:在解压前检查目标路径下文件是否存在。如果存在,则跳过该文件的解压,不进行覆盖操作。
- 并发控制:使用
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
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
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
by Anthropicaccess
Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
by Anthropicconfigure
Set up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
by Anthropicaccess
Manage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
by Anthropic