npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

reg-mover

v1.1.0

Published

A powerful command-line tool to move files based on regex pattern matching

Readme

Regex File Mover

一个强大的命令行工具,可以根据正则表达式模式匹配文件并批量处理。

功能特性

  • ✅ 基于正则表达式匹配文件名
  • ✅ 支持指定扫描目录(默认当前目录)
  • ✅ 只扫描当前目录,不递归子目录
  • ✅ 自动处理文件名冲突(添加序号)
  • 5种文件操作方式
    • 📁 移动到指定目录
    • 📦 压缩并移动(ZIP)
    • 📅 时间戳重命名
    • ✏️ 自定义重命名(支持变量)
    • 🗑️ 删除文件
  • ✅ 彩色终端输出,清晰易读
  • ✅ 交互式确认,防止误操作
  • ✅ 跨平台支持(Windows、macOS、Linux)

安装

全局安装

npm install -g regex-file-mover

本地安装

npm install regex-file-mover
npx regex-mover

使用方法

基本用法

regex-mover

交互式操作流程

  1. 输入正则表达式

    请输入正则表达式来匹配文件名:
    > \.txt$    # 匹配所有以 .txt 结尾的文件
  2. 输入扫描目录

    请输入要扫描的目录路径(直接回车使用当前目录):
    > D:\MyFiles    # 可选,直接回车使用当前目录
  3. 查看匹配结果

    找到 15 个文件/文件夹
    匹配到 5 个文件:
    
    1. document.txt
    2. notes.txt
    3. data.txt
    4. report.txt
    5. archive.txt
  4. 选择操作类型

    === 选择操作类型 ===
    1. 移动到指定目录
    2. 压缩并移动
    3. 时间戳重命名
    4. 自定义重命名
    5. 删除文件
    0. 取消操作
    
    请选择操作:
    > 1
  5. 根据操作类型输入必要信息

    移动到指定目录:

    请输入目标目录路径:
    > D:\MovedFiles
    
    是否保留目录结构? (y/n)
    > y

    压缩并移动:

    请输入目标目录路径:
    > D:\Backups
    
    是否自定义 ZIP 文件名? (y/n)
    > y
    
    请输入 ZIP 文件名:
    > my_backup_20260409
    
    开始压缩并移动文件到: D:\Backups
    ✓ 已创建压缩包: my_backup_20260409.zip (123456 bytes)
    ✓ 已清理临时目录: C:\Users\...\temp_1712678901234

    时间戳重命名:

    请输入重命名前缀(可选,直接回车跳过):
    > backup_
    
    是否覆盖已存在的文件? (y/n)
    > n
    
    开始时间戳重命名
    ✓ test1.txt -> backup_2026-04-09T11-30-45-123Z.txt
    ✓ test2.txt -> backup_2026-04-09T11-30-45-124Z.txt

    自定义重命名:

    请输入命名规则模板(支持变量: {name}, {ext}, {index}, {timestamp}, {counter}):
    > file_{index}_{timestamp}.txt
    
    是否覆盖已存在的文件? (y/n)
    > n
    
    开始自定义重命名
    ✓ test1.txt -> file_1_2026-04-09T11-30-45-123Z.txt
    ✓ test2.txt -> file_2_2026-04-09T11-30-45-124Z.txt

    删除文件:

    即将删除以下文件:
    1. test1.txt
    2. test2.txt
    3. test3.txt
    
    共 3 个文件
    确认删除? (y/n)
    > y
    
    ✓ 已删除: test1.txt
    ✓ 已删除: test2.txt
    ✓ 已删除: test3.txt
  6. 查看结果

    === 操作完成 ===
    ✓ 成功: 5 个文件
    ✗ 失败: 0 个文件

正则表达式示例

| 模式 | 说明 | |------|------| | \.txt$ | 匹配所有 .txt 结尾的文件 | | ^test | 匹配所有以 test 开头的文件 | | \.jpg|\.png | 匹配所有 jpg 或 png 图片 | | .*\.log$ | 匹配所有 .log 结尾的文件 | | backup_\d{4} | 匹配所有 backup_2023、backup_2024 等文件 |

自定义重命名变量

在自定义重命名功能中,支持以下变量:

  • {name} - 文件名(不含扩展名)
  • {ext} - 文件扩展名
  • {index} - 序号(从1开始)
  • {timestamp} - 当前时间戳
  • {counter} - 计数器(从1开始)

示例模板

  • backup_{timestamp}.txt - 添加时间戳
  • file_{index}.jpg - 添加序号
  • data_{name}_{timestamp}.csv - 组合多个变量
  • photo_{counter}_{name}.png - 使用计数器

命令行参数

目前版本为交互式操作,无需参数。

注意事项

  • ⚠️ 移动操作不可撤销,请确认后再执行
  • ⚠️ 如果目标文件已存在,会自动添加序号(如:file_1.txt)
  • ⚠️ 只扫描指定目录的直接内容,不会递归子目录
  • ⚠️ 删除文件前会显示文件列表并要求二次确认
  • ⚠️ 压缩功能会创建临时目录,操作完成后会自动清理

开发

本地开发

# 克隆仓库
git clone https://github.com/yourusername/regex-file-mover.git
cd regex-file-mover

# 安装依赖
npm install

# 运行
node index.js

测试

# 运行测试脚本
node test-enhanced.js

发布到 npm

# 登录 npm
npm login

# 发布
npm publish

依赖包

  • readline-sync - 交互式命令行输入
  • archiver - 文件压缩功能

许可证

MIT

贡献

欢迎提交 Issue 和 Pull Request!

作者

Your Name

更新日志

v2.0.0 (2026-04-09)

  • ✨ 新增压缩并移动功能
  • ✨ 新增时间戳重命名功能
  • ✨ 新增自定义重命名功能(支持变量替换)
  • ✨ 新增删除文件功能
  • ✨ 新增操作菜单系统
  • ✨ 新增保留目录结构选项
  • 📝 更新文档和示例

v1.0.0 (2026-04-09)

  • 初始版本发布
  • 支持正则表达式匹配文件
  • 支持指定扫描目录
  • 跨平台支持