← 返回
未分类 中文

rename-fill

Rename files in a specified directory with a given prefix. This skill prompts the user for a prefix and directory path, shows a preview of changes, and asks...
在指定目录中用给定前缀重命名文件。该技能会提示用户输入前缀和目录路径,显示更改预览,并询问...
git-xyz git-xyz 来源
未分类 clawhub v1.0.0 1 版本 100000 Key: 无需
★ 0
Stars
📥 551
下载
💾 0
安装
1
版本
#latest

概述

Rename File Skill

This skill renames all files in a specified directory by adding a prefix to each filename. It shows a preview of changes and asks for user confirmation before executing the rename operation.

When to use this skill

Use this skill when:

  • User wants to batch rename files in a directory
  • User needs to add a consistent prefix to multiple files
  • User wants to preview changes before applying them
  • User wants a safe, interactive file renaming tool

Prerequisites

The skill uses a JavaScript script for file operations, which requires Node.js to be installed.

Implementation steps

1. Ask for user inputs

Use AskUserQuestion to get:

  1. Prefix: What prefix should be added to the filenames?
  2. Directory path: Which directory contains the files to rename? (Enter absolute or relative path)
  3. Confirmation: Show preview and ask for confirmation before proceeding

Example AskUserQuestion call for prefix and directory:

{
  "questions": [{
    "question": "What prefix should be added to the filenames?",
    "header": "Prefix",
    "options": [
      {"label": "Enter custom prefix", "description": "I'll type a prefix (e.g., 'photo_', 'backup_')"}
    ],
    "multiSelect": false
  }, {
    "question": "Which directory contains the files to rename?",
    "header": "Directory",
    "options": [
      {"label": "Current directory", "description": "Use current working directory"},
      {"label": "Custom path", "description": "I'll specify a different directory"}
    ],
    "multiSelect": false
  }]
}

2. Process user inputs

After getting answers:

  • Prefix: Use the user-provided prefix (sanitize if needed)
  • Directory path:
  • If "Current directory" selected, use current working directory
  • If "Custom path" selected, ask user to enter the path via a follow-up question
  • Validate that the directory exists and is readable

3. Generate preview

Read the directory contents and generate a preview of rename operations:

  • List all files (excluding directories) in the target directory
  • Show current filename → new filename mapping
  • Count total files to be renamed

Display the preview to the user and ask for confirmation:

{
  "questions": [{
    "question": "Preview: ${count} files will be renamed with prefix '${prefix}'. Proceed?",
    "header": "Confirmation",
    "options": [
      {"label": "Yes, rename files", "description": "Execute the rename operation"},
      {"label": "No, cancel", "description": "Cancel without making changes"}
    ],
    "multiSelect": false
  }]
}

4. Execute rename operation

If user confirms, run the JavaScript rename script:

# Get the path to this skill directory
SKILL_DIR="$(dirname "$0")/rename-file"

# Run the JavaScript rename script
node "$SKILL_DIR/scripts/rename-files.js" "<prefix>" "<directory-path>"

5. Display results

Show the user:

  • Number of files successfully renamed
  • Any errors encountered
  • Summary of changes made

Script details

The JavaScript script (scripts/rename-files.js):

  1. Validates the directory exists and is accessible
  2. Reads all files in the directory (excluding subdirectories)
  3. For each file, constructs new filename by prepending the prefix
  4. Performs the rename operation using fs.renameSync
  5. Handles errors gracefully (e.g., permission issues, duplicate names)
  6. Returns success/failure status

Error handling

  • If directory doesn't exist or is not accessible, show error and abort
  • If no files found in directory, inform user and exit
  • If a file with the new name already exists, skip that file and report
  • If permission denied for any file, skip and report error
  • Rollback on critical errors (optional, can be implemented)

Safety features

  • Always shows preview before making changes
  • Asks for explicit confirmation
  • Skips directories (only renames files)
  • Preserves file extensions
  • Reports all operations for transparency

Usage example

User: /rename-file
Assistant: Asks for prefix and directory
User: Prefix: "vacation_", Directory: "./photos"
Assistant: Shows preview: "photo1.jpg" → "vacation_photo1.jpg", etc.
User: Confirms
Assistant: Renames files and shows summary

版本历史

共 1 个版本

  • v1.0.0 当前
    2026-05-03 06:35 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

dev-programming

Mcporter

steipete
使用 mcporter CLI 直接列出、配置、认证及调用 MCP 服务器/工具(支持 HTTP 或 stdio),涵盖临时服务器、配置编辑及 CLI/类型生成功能。
★ 195 📥 67,513
dev-programming

YouTube

byungkyu
使用托管OAuth集成YouTube Data API,支持搜索视频、管理播放列表、获取频道数据及评论互动,适用于用户需要时使用此技能。
★ 142 📥 41,432
dev-programming

CodeConductor.ai

larsonreever
AI驱动平台,提供快速全栈开发、智能体、工作流自动化及低代码AI集成的可扩展产品创建。
★ 72 📥 181,607