Skip to main content

Bulk-rename, copy and delete files using a text editor

Project description

  • Verifies validity of changes before anything is applied.

  • No restrictions for encoding in filenames. ASCII control characters and invalid UTF-8 are escaped.

  • Deletions can be reverted until the menu is closed.

  • Fully interactive mode allows reverting any changes until menu is closed.

  • In case an error occurs (e.g. insufficient permissions) any changes can be reverted.

Installing

Basic Usage

Pass files to rename to mved:

mved *.txt

An editor ($VISUAL or $EDITOR) is started with a list of files:

1 one.txt
2 two.txt

Every filename is listed with a number separated by a single space.

  • To rename or move a file, change its path after the number.

  • To copy a file, duplicate the line including the number and change the path. The original can be preserved or moved as well.

  • To delete a file, delete the line including the number.

  • Lines starting with # are ignored, so adding # before the number would also delete it.

After saving the file and closing the editor, if the changes are valid, the modifications are applied immediately. If there were no deletions, mved exits.

If there were deletions, the menu is shown:

[revert/dryrun/quit] >

No files were deleted yet, only moved to a temporary location.

  • revert immediately reverts all files to their original locations.

  • dryrun prints what revert would do without touching files.

  • quit closes the menu and finally deletes any files that were removed with the editor. Pressing CTRL-D is equivalent to quit.

Conflicts

After editing the file list, conflicts may be detected and the changes cannot be applied. In that case, the conflicts are listed and the menu is shown:

[conflicts/diff/edit/reset/quit] >

No changes have been applied yet. Enter edit to resolve conflicts by editing the file list. See Menu for further usage.

The following kinds of conflicts may be detected:

  • destination conflict

    Two files in the list have the same destination filename.

    Enter edit to resolve the conflicts in the editor.

  • file exists

    A destination file already exists that was not passed to mved. Enter add to add the destination files to the list and edit to resolve the conflicts by moving the added files.

  • path exists

    Part of a destination path already exists and is not a directory.

  • invalid filename

    A filename on the list is invalid.

    Enter edit to change invalid filenames in the editor.

  • cannot copy/delete directory

    Copying and deleting whole directories is not supported.

  • directory conflict

    A modified directory path is part of the source or destination of other files. Such changes currently are not supported. Try making the changes with separate invocations of mved.

Escapes

ASCII control characters and invalid UTF-8 are converted to an escaped representation in the file list.

Escape sequences are initiated with the \ (backslash) character. Anything else is left unmodified. Literal backslashes in filenames must be doubled.

The replaced control characters are:

  • 0-31 (0 to 0x1f inclusive)

  • 127 (0x7f)

The following table lists available escape sequences. The Escape column lists the escape sequence understood by mved. All other columns are for reference only.

Escape

Abbr.

Caret Notation

Hex

Dec

Description

\a

BEL

^G

07

7

Bell

\b

BS

^H

08

8

Backspace

\t

TAB

^I

09

9

Horizontal Tabulation (Tab)

\n

LF

^J

0a

10

Line Feed

\v

VT

^K

0b

11

Vertical Tabulation

\f

FF

^L

0c

12

Form Feed

\r

CR

^M

0d

13

Carriage Return

\\

5c

92

Backslash

\x00 .. \xff

00 .. ff

0 .. 255

Arbitrary octet

Any byte value can be specified with \x followed by two hexadecimal digits representing its value, ranging from \x00 to \xff.

Note that \x escape sequences specify literal octets and are not encoded to UTF-8. Values above \x7f will result in invalid UTF-8 unless constructed in a conforming manner. To specify code points above U+007F, enter literal UTF-8 in the editor.

Note that even though \x00 can be specified, it is not allowed in filenames.

Advanced Options

Interactive Mode

Passing -i/--interactive to mved starts interactive mode. In this mode, the menu is shown after every action. After editing, changes can be inspected with diff or dryrun, edited with edit or reset or accepted with apply. After apply, all changes can be undone with revert, even if there were no deletions.

Recursion Depth

The -l/--levels, -d, and -r options control the recursion depth for directories passed to mved.

  • -l/--levels sets the recursion depth to the given number.

    The default is 1. This means for files passed to mved that are directories, the contained files are added.

  • -r recurses infinitely. All files in the hierarchy are listed.

  • -d disables recursion. This can be used to rename given directories.

Editor

The -e/--editor option specifies the interactive editor command. It is also used when entering the edit and reset menu commands without argument. The default is taken from the environment:

  • $VISUAL is used, if it is set.

  • Otherwise, $EDITOR is used, if it is set.

  • If both are unset, vi is used.

The command is run with /bin/sh. The file to edit is added as the last argument.

Stream Editor

The -E/--stream-editor option or entering edit |<command> in the menu runs the given command as a stream editor. The command receives the file list on its stdin and must print the result to stdout. The format is the same as with the interactive editor. The command is run with /bin/sh.

For example, to replace all occurrences of one with two, run:

mved -E 'sed s/one/two' *.txt

This is only applied on startup, in place of the initial interactive editor call.

To do the same in the menu, enter

edit |sed s/one/two

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mved-0.7.0.tar.gz (37.2 kB view details)

Uploaded Source

Built Distribution

mved-0.7.0-py3-none-any.whl (36.4 kB view details)

Uploaded Python 3

File details

Details for the file mved-0.7.0.tar.gz.

File metadata

  • Download URL: mved-0.7.0.tar.gz
  • Upload date:
  • Size: 37.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.10.4

File hashes

Hashes for mved-0.7.0.tar.gz
Algorithm Hash digest
SHA256 796c830d3126497ae001bcb8f15a9d7d75f2f7c91b1b0ecd853833c113f1f4fb
MD5 c70ee09eae9048f3e6991173bade08ff
BLAKE2b-256 e121f641c1d874badea1073211dede626bcadec0f08d11e76e82a9c2daf72514

See more details on using hashes here.

File details

Details for the file mved-0.7.0-py3-none-any.whl.

File metadata

  • Download URL: mved-0.7.0-py3-none-any.whl
  • Upload date:
  • Size: 36.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.10.4

File hashes

Hashes for mved-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 91000f1211b4fe6d88e088f3703ca0dd8b5095bfddf26fc6cb29015c85895e06
MD5 53ac526b9bcb20ba3569b8a89f20807b
BLAKE2b-256 eeb76a0ad4bf01de4b8bfd358f9ae5ea06a09d8abe7265d2b009e556469dead4

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page