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 🙏

© 2024 – Pkg Stats / Ryan Hefner

file-refacto

v0.0.4

Published

CLI tool to rename files based on their extension

Downloads

377

Readme

File Refacto CLI

File Refacto is a simple CLI tool that helps you rename files in a directory based on their extension and a new filename, or change the file extension recursively. This tool also allows renaming files in serial order using a wildcard pattern, making it perfect for organizing and renaming files in bulk across multiple subdirectories.

Features

  • Rename files with a specific extension.
  • Change the extension of files in a directory.
  • Rename files using a wildcard pattern (e.g., brand-* for brand-1, brand-2).
  • Traverse directories and subdirectories recursively.
  • Preserve the file extension while renaming.

Requirements

  • Node.js: Make sure you have Node.js installed. You can download it from Node.js official site.
  • npm: Installed by default with Node.js.

Installation

Install the tool globally via npm:

npm install -g file-refacto

Usage

Once installed globally, you can use the file-refacto command with various options to rename files or change file extensions. The CLI provides three main commands:

  1. rename: Rename files by their extension and a new filename.
  2. change-ext: Change the extension of files in a directory.
  3. rename-all: Rename files in serial order using a wildcard pattern.

Commands

1. Rename Files

This command allows you to rename files with a specific extension to a new filename while preserving their extension.

file-refacto rename <directory> <extension> <newname>
  • directory: The root directory to start from.
  • extension: The file extension to target (e.g., .md, .txt, .json).
  • newname: The new base name for the files (without the extension).

Example:

If you want to rename all .md files to README.md in the /my-project directory:

file-refacto rename /my-project .md README

This will find all .md files and rename them to README.md in each directory.

2. Change File Extension

This command changes the file extension of all files in a directory recursively.

file-refacto change-ext <directory> <newext>
  • directory: The root directory to start from.
  • newext: The new extension to apply (e.g., .txt, .json).

Example:

Change all files in /my-project/assets from .jpg to .png:

file-refacto change-ext /my-project/assets .png

This will change all file extensions in the directory from .jpg to .png.

3. Rename Files Using Wildcard Pattern

This command renames files in serial order using a wildcard pattern. The * in the pattern is replaced with sequential numbers.

file-refacto rename-all <directory> <extension> <pattern>
  • directory: The root directory to start from.
  • extension: The file extension to target (e.g., .png).
  • pattern: The pattern for the new filenames. The * is replaced with a number (e.g., brand-* becomes brand-1, brand-2, etc.).

Example:

Rename all .png files in /my-project/assets to brand-*, starting from 1:

file-refacto rename-all /my-project/assets .png brand-*

This will rename files like brand-1.png, brand-2.png, and so on.

Command Breakdown

  • directory: The starting directory for the file renaming or extension changing process.
  • extension/newext: The file extension to rename or change (e.g., .md, .txt).
  • newname/pattern: The new name for the files (excluding the extension) or a pattern for serial renaming.

Example Output

When the tool runs, you'll see logs like this:

Renamed /my-project/docs/file1.md to /my-project/docs/README.md
Renamed /my-project/src/file2.md to /my-project/src/README.md
Changed /assets/image1.jpg to /assets/image1.png
Renamed /assets/brand.png to /assets/brand-1.png

Version History

  • 0.0.4:
    • Added rename-all command to rename files in serial order using a wildcard pattern.
    • Improved error handling and extension validation.
    • Skips files when the target extension already exists in the directory.
    • Ensures wildcard pattern * is replaced with serial numbers for file renaming.

Contributing

Contributions are welcome! Fork the repository, make your changes, and open a pull request.

License

This project is licensed under the MIT License. See the LICENSE file for more information.

Issues and Support

If you encounter any issues, feel free to open an issue on the GitHub repository. We’ll address it as soon as possible.