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

mvmv

v0.9.9

Published

Batch moving and renaming files using globbing patterns.

Downloads

33

Readme

Build Status Build status Known Vulnerabilities Coverage Status License: MIT

mvmv

A NodeJS package that performs batch renaming and moving of files, with support for globbing wildcards * and ?.

You can use the package by importing it into your NodeJS scripts or as a command on the terminal.

Note:

Go on github for the latest version of this documentation.

Motivation

The typical implementations of the linux mv command do not support this rather intuitive usage:

> mv *.txt *.old

Installation

Installation is straightforward, as with most NPM packages.

Install mvmv globally to use it as a command line tool anywhere on the command console:

> npm install -g mvmv

Install it as a dependency to use it in your code:

> npm install --save mvmv

In-code Usage

mvmv.exec(src, dst, cb) accepts a callback and returns the number of successful files moved (returns NULL if file not found).

The callback is invoked after a move/rename attempt on an individual file. The arguments passed to the callback are: error, oldPath, newPath, index. index is the zero-based position of the file in the batch of files to be processed.

Example
const mvmv = require('mvmv').create();

mvmv.exec('*.txt', 'temp/*.old');

:baby: New in v0.9.9:

mvmv.execAsync(src, dst) is the async counterpart of mvmv.exec(). execAsync() returns a Promise. The Promise resolves to the number of files successfully moved. In case of errors, the Promise rejects to an Array of Error.

Example
const mvmv = require('mvmv').create();

mvmv.execAsync('*.txt', 'temp/*.old')
    .then(res => console.log(`Moved ${res} files.`))
    .catch(errors => errors.forEach(e => console.log(e)));

// In an async function
async function moveFiles(src, dst) {
    try {
        console.log(await mvmv.execAsync(src, dst));
    }
    catch (errors) {
        errors.forEach(e => console.log(e));
    }
}

Command-line Usage

With package installed globally:

> mvmv '*.txt' 'temp/*.old'

Execute the mvmv command without argument to display the usage information:

  Usage: mvmv [options] <source> <target>

  mvmv command moves (or renames) files specified by <source> to destination names specified by <target>.
  mvmv supports * and ? globbing wildcards for specifying file names pattern.
  If wildcards are used, <source> and <target> must be wrapped in quotes.
  Multiple consecutive * wildcards in <source> are treated as one single * wildcard.
  The file will not be moved if a file with the same name already exists at the target location.


  Options:

    -V, --version      output the version number
    -i, --interactive  Prompts for confirmation before each move operation.
    -s, --simulate     Dry-runs the move operations without affecting the file system.
    -v, --verbose      Prints additional operation details.
    -h, --help         output usage information
Tip!

You can invoke mvmv without prior installing it by using npx (bundled with NPM since v5.2.0):

> npx mvmv '*.txt' 'temp/*.old'

Caveats

  • mvmv does not overwrite existing files.
  • mvmv treats consecutive * wildcard in the source glob pattern as a single *. (This does not apply to the destination glob pattern.)
  • globbing patterns on the command line must be enclosed in quotes to prevent wildcard expansion by the shell. An alternative is to turn shell globbing off. See StackOverflow thread for more information.

How It Works

Wildcards in the destination glob pattern correspond to the wildcards of the same type appearing in the source glob pattern, matched by the order in which they appear.

Example
mvmv '**-*-lines-*?-*?.txt' '*_*-lines-s?e?.txt'
      |  |        |  |       | |        | |
      |  |        |  +-------|-|--------|-+
      |  |        +----------|-|--------+
      |  +-------------------|-+
      +----------------------+

(Reminder: consecutive * wildcards in the source glob pattern are treated as a single *.)

Demonstration

mvmv-demo2