GREN - rename files using regular expressions

Submit command line tools that you find here.
Post Reply
Message
Author
User avatar
lintalist
Posts: 434
Joined: Sat Apr 19, 2014 12:52 am
Contact:

GREN - rename files using regular expressions

#1 Post by lintalist »

Website is offline but you can download the program from the Internet Archive, https://web.archive.org/web/20021202122 ... /gren.html
GREN is a command-line utility for Windows 9x/2000 that finds and/or renames files. I often felt that the DOS rename command had severe limitations. This gave the motivation to write GREN.

GREN can do all things DOS's RENAME can. However, GREN's power comes from being able to understand Perl's regular expressions (REGEXPs). Perl programmers are well aware of the power of REGEXPs as a pattern matching and replacing tool. GREN fully supports Perl's REGEXPs.

In all documentation pages you will see that string substitution in Perl is done with the following construct:

s/<FindString>/<ReplaceString>/[options]

This is exactly what happens inside GREN. <FindString>, <ReplaceString> is the first and second argument at the command line. I hope this helps to interpret the online documentation. [options] are switches modifying the matching process. The most common one is i. This switches on the case-insensitive match. Another common switch is g, which forces matching of all occurrences of a pattern in a string. By default matching is case-sensitive and stops on the first occurrence of the pattern in a string (i.e. not global).

To use GREN, you have to call it as follows:

GREN [-i|g|s|r|p|a] [-f "FileName"] "FindString" ["ReplaceString"]

You have to type the double-quotes if strings contain spaces
FindString String or REGEXP to search for in the filename
ReplaceString String or REGEXP to replace with

Supported switches
i case-insensitive match OFF
g global match (i.e. replace all occurrences)
s search in subdirectories
r rename read-only files
p preview of changes OFF
a gets all files with the initial DOS query
f operates on list of filenames read from file <FileName>

Option switches can be grouped for convenience. That is you may set the i and g together as -ig instead of -i -g. The switches must precede all arguments. All parameters after the switches are taken as arguments.

GREN supports two modes of operation: Find-Only mode and Rename mode. The first can be used just to find out which filenames match a specific pattern. This mode is automatically selected when you invoke GREN with just one argument containing the matching pattern. By giving two arguments you select the Rename mode. Under this mode GREN finds all filenames that match the pattern specified by the first argument and renames them according to the pattern given in the second argument.

Sort usage instructions can be displayed on screen by simply typing GREN with no arguments and press ENTER.
The exe is just a compiled perl script afaik.

User avatar
Midas
Posts: 6705
Joined: Mon Dec 07, 2009 7:09 am
Location: Sol3

Re: GREN - rename files uses regular expressions

#2 Post by Midas »

Quick note to point to (also dead) non-CLI awxRename Windows shell extension, which also does RegExes and is currently my daily driver: viewtopic.php?p=69649#p69649.

User avatar
lintalist
Posts: 434
Joined: Sat Apr 19, 2014 12:52 am
Contact:

Re: GREN - rename files using regular expressions

#3 Post by lintalist »

I now use the Multi rename tool of my file manager, but I used GREN in batch files for a while and it worked well, there wasn't that much available then. (Now I often use AutoHotkey so no specific requirement for GREN anymore)

User avatar
lintalist
Posts: 434
Joined: Sat Apr 19, 2014 12:52 am
Contact:

Re: GREN - rename files using regular expressions

#4 Post by lintalist »

Similar:

RenameRegex (RR) is a Windows command-line bulk file and directory renamer, using regular expressions. You can use it as a simple file renamer or with a complex regular expression for matching and replacement.

Website: https://github.com/nicjansma/rename-regex
Download: https://github.com/nicjansma/rename-reg ... bin/RR.exe

Code: Select all

 RR.exe file-match search replace [/p] [/r] [/f] [/e] [/files] [/dirs]
        /p: pretend (show what will be renamed)
        /r: recursive
        /f: force overwrite if the file already exists
        /e: preserve file extensions
    /files: include only files
     /dirs: include only directories
            (default is to include files only, to include both use /files /dirs)
Example, Remove all numbers from the file names:

Code: Select all

RR.exe * "[0-9]+" ""

User avatar
lintalist
Posts: 434
Joined: Sat Apr 19, 2014 12:52 am
Contact:

Re: GREN - rename files using regular expressions

#5 Post by lintalist »

Similar:

BK Renamer — Renames all files in a directory, based on a regular expression.

Website: https://web.archive.org/web/20070704032 ... m/renamer/
Download: https://web.archive.org/web/20070704032 ... ren100.zip
( backup http://reimagery.com/fsfd/bin/filutil1/bkren100.zip )

bkren [-s] "searchexpression" "replaceexpression"

Examples

Code: Select all

 bkren "(.*)\.htm" "\1.html"
  (Change all files/folders in the current directory with the .htm
   extension to have the .html extension.)

bkren "(.*)\.([^.]*)" "\1_backup.\2"
  (Appends _backup to all filenames, but before the file extension.
   For example, changes bkren.txt to bkren_backup.txt and test.html
   to test_backup.html.)

bkren -s "(.*)100(.*)" "\1303\2"
  (... go through all filenames in the current directory and all
   subdirectories and change all instances of "100"...to "303".
   For example...bkren100.zip to bkren303.zip...100monkeys.gif to
   303monkeys.gif.)
Edit: update link to original archived website, ht vevy
Last edited by lintalist on Wed Dec 30, 2020 9:02 am, edited 1 time in total.

User avatar
vevy
Posts: 795
Joined: Tue Sep 10, 2019 11:17 am

Re: GREN - rename files using regular expressions

#6 Post by vevy »

lintalist wrote: Tue Dec 29, 2020 12:01 pm BK Renamer
Original site.

User avatar
lintalist
Posts: 434
Joined: Sat Apr 19, 2014 12:52 am
Contact:

Re: GREN - rename files using regular expressions

#7 Post by lintalist »

Untested but I had it bookmarked

Bulk Rename Command is the free command-line version of Bulk Rename Utility - https://www.bulkrenameutility.co.uk/

With Bulk Rename Command (BRC) you can:

* Create scheduled jobs using the Windows Scheduler.
* Perform specific tasks repetitively without user intervention.

Version 1.3.3.0 for Windows 10, 8, 7, Vista, XP, Server 2019, 2016, 2012, 2008, 2003, 2000. Application files in a compressed zip file (no installer). The manual is included in the ZIP file:

https://www.bulkrenameutility.co.uk/Dow ... ode_32.zip
https://www.bulkrenameutility.co.uk/Dow ... ode_64.zip
The following are processed in the sequence you specify them:

APPENDDATE - Append a date/time. Specify as
/APPENDDATE:Type(C|M|A|N):Mode(P|S|B):Separator:Segment:Format:(Custom)
where C=Created, M=Modified, A=Access, N=Now.
Seg is the text to place between the elements.
Format is between 1 and 10.
Custom Format is optional

APPENDFOLDER - Append the parent folder name(s). Specify as
/APPENDFOLDER:Mode(P|S|B):Separator:Levels
where P=Prefix, S=Suffix, B=Prefix and Suffix
Levels is the number of folder levels to append.

AUTONUMBER - Append an autonumber. Specify as
/AUTONUMBER:Start:Increment:Mode(P|S|B):Separator:Base:Pad
where P=Prefix, S=Suffix, B=Prefix and Suffix
Base is 2 to 36; Pad is the number of digits to pad.

CHANGECASE:Mode - Change Case. Specify Mode as:
L - Lower Case
U - Upper Case
T - Title Case
S - Sentence Case

CHANGEEXTCASE:Mode - Change Case of the extension. Specify Mode as:
L - Lower Case
U - Upper Case
T - Title Case
S - Sentence Case

COPYFIRSTN:Value - Copy the first n chars to a buffer, for subsequent paste

COPYLASTN:Value - Copy the last n chars to a buffer, for subsequent paste

CUTFIRSTN:Value - Cut the first n chars to a buffer, for subsequent paste

CUTLASTN:Value - Cut the last n characters to a buffer, for subsequent paste

FIXEDNAME:Value - Set the name to a fixed value

FIXEDEXT:Value - Set the extension to a fixed value

INSERT:Value:Pos - Insert text <value> at<Pos>

PASTEATSTART - Paste buffer (created with a previous copy/cut) to the start

PASTEATEND - Paste buffer (created with a previous copy/cut) to the end

PASTEATPOS:Pos - Paste buffer (created with a previous copy/cut) to pos

PREFIX:Value - Prefix the name with <value>

REMOVEDOTS - Remove leading dots (. and ..) from a name

REMOVEEXT - Completely remove the filename extension

REMOVENAME - Completely remove the filename

REMOVEFIRSTN:Value - Remove the first <value> characters

REMOVEFROMTO:Value - Remove characters from positions <from> to <to>

REMOVELASTN:Value - Remove the last <value> characters

REGEXP:Match:Replace - Perform Regular Expression find and replace ( notation)

REPLACECI:Old:New - Case-insensitive find & replace

REPLACECS:Old:New - Case-sensitive find & replace

STRIPACCENTS: Strip all accented characters

STRIPCHARS:Strip all alphabetic characters

STRIPDIGITS:Strip all digits

STRIPHIGH - Strip all high characters (above 127)

STRIPSYMBOLS - Strip all symbols

SUFFIX:Value - Suffix the name with <value>

TIDYDS - Tidy all double-spaces (and replace with single spaces)


The following can be invoked at any time, and affect the entire operation:
CLEARA - Clear the Archive flag after processing eligible entries
CLEARR - Clear the Read-only flag after processing eligible entries
CLEARS - Clear the System flag after processing eligible entries
CLEARH - Clear the Hidden flag after processing eligible entries
DIR - Directory to process. If not specified, defaults to current folder
EXECUTE - Actually perform the rename (otherwise no updates will be done)
IGNOREFOLDERX - Ignore folders extensions, and operate on the entire name
IGNOREFILEX - Ignore file extensions, and operate on the entire name
INCLR - Include ReadOnly items (excluded by default)
INCLS - Include System items (excluded by default)
INCLH - Include Hidden items (excluded by default)
MAXLEN:Value - Only select files/folders with names <value> or shorter

MINLEN:Value - Only select files/folders with names <value> or longer

NODUP - Prevent duplicate names by appending numeric suffixes if required
NOFILES - Do not attempt to rename Files
NOFOLDERS - Do not attempt to rename Folders
PATTERN - Files to match. Separate values with spaces (e.g. *.jpg *.tif)
QUIET - Do not list the filenames as they are being changed.
RECURSIVE - Process folders and sub-folders
SETA - Set the Archive flag after processing eligible entries
SETR - Set the Read-only flag after processing eligible entries
SETS - Set the System flag after processing eligible entries
SETH - Set the Hidden flag after processing eligible entries
SORTBY:Mode - Sort the files before renaming. Specify Mode as:
N - Filename (default)
C - Created Date
M - Modified Date
A - Accessed Date
S - Size
R - Random

SORTDESC - Sort the entries in descending order

User avatar
lintalist
Posts: 434
Joined: Sat Apr 19, 2014 12:52 am
Contact:

Re: GREN - rename files using regular expressions

#8 Post by lintalist »

Untested, just found, same dev as csvtk,

brename - A practical cross-platform command-line tool for safely batch renaming files/directories via regular expression
Website: https://github.com/shenwei356/brename
Download: https://github.com/shenwei356/brename/releases/ (32/64 bit)

Just download compressed executable file of your operating system, and decompress the TAR.GZ file

Features
  • Cross-platform. Supporting Windows, Mac OS X and Linux.
  • Safe. By checking potential conflicts and errors.
  • Supporting Undo.
  • Overwrite can be detected and users can choose whether overwrite or leave it.
  • File filtering. Supporting including and excluding files via regular expression. No need to run commands like find ./ -name "*.html" -exec CMD.
  • Renaming submatch with corresponding value via key-value file.
  • Renaming via ascending integer.
  • Recursively renaming both files and directories.
  • Supporting dry run.
  • Colorful output.
Flags:
-d, --dry-run print rename operations but do not run
-F, --exclude-filters strings exclude file filter(s) (regular expression, NOT wildcard). multiple values supported, e.g., -F ".html" -F ".htm", but ATTENTION: comma in filter is treated as separator of multiple filters
-U, --force-undo continue undo even when some operations failed
-h, --help help for brename
-i, --ignore-case ignore case of -p/--pattern, -f/--include-filters and -F/--exclude-filters
-e, --ignore-ext ignore file extension. i.e., replacement does not change file extension
-f, --include-filters strings include file filter(s) (regular expression, NOT wildcard). multiple values supported, e.g., -f ".html" -f ".htm", but ATTENTION: comma in filter is treated as separator of multiple filters (default [.])
-D, --including-dir rename directories
-K, --keep-key keep the key as value when no value found for the key
-I, --key-capt-idx int capture variable index of key (1-based) (default 1)
-m, --key-miss-repl string replacement for key with no corresponding value
-k, --kv-file string tab-delimited key-value file for replacing key with value when using "{kv}" in -r (--replacement)
-l, --list only list paths that match pattern
-a, --list-abs list absolute path, using along with -l/--list
-s, --list-sep string separator for list of found paths (default "\n")
--max-depth int maximum depth for recursive search (0 for no limit)
-N, --nature-sort list paths in nature sort, using along with -l/--list
--nr-width int minimum width for {nr} in flag -r/--replacement. e.g., formating "1" to "001" by --nr-width 3 (default 1)
--only-dir only rename directories
-o, --overwrite-mode int overwrite mode (0 for reporting error, 1 for overwrite, 2 for not renaming) (default 0)
-p, --pattern string search pattern (regular expression)
-q, --quiet be quiet, do not show information and warning
-R, --recursive rename recursively
-r, --replacement string replacement. capture variables supported. e.g. $1 represents the first submatch. ATTENTION: for *nix OS, use SINGLE quote NOT double quotes or use the \ escape character. Ascending integer is also supported by "{nr}"
-n, --start-num int starting number when using {nr} in replacement (default 1)
-u, --undo undo the LAST successful operation
-v, --verbose int verbose level (0 for all, 1 for warning and error, 2 for only error) (default 0)
-V, --version print version information and check for update

Post Reply