FixNames plugin for Take Command / TCC / TCC/LE

beta version 0.45.1     2024-05-06

Charles Dye

Purpose:

This plugin provides one new command FIXNAMES to rename filenames containing troublesome characters. By “troublesome” I mean those characters which are especially difficult to handle in TCC: percent signs, carets, and grave accents.

Installation:

To use this plugin, copy FixNames.dll to some known location on your hard drive. (If you are using the 32-bit version of Take Command, take FixNames-x86.dll instead.) Load the plugin with a PLUGIN /L command, for example:

plugin /l c:\bin\tcmd\fixnames\fixnames.dll

If you copy the .DLL file to a subdirectory named PlugIns within your Take Command program directory, it will be loaded automatically when TCC starts.

New Command:

FIXNAMES — Rename files to remove troublesome characters.

Syntax:
FIXNAMES /A /B /C /D /E /F /H /K:bp /N /N:flags /P /Q:from-list /R:to-list /S /U filespec…

/Areplace Ampersands with underscores
/Breplace Blanks (spaces) with underscores
/Creplace parentheses with underscores
/Drename Directories, not files
/Edecode =XX hexadecimal pairs
/Freplace all ASCII apostrophes, quotes, and backquotes with underscores
/Hdecode HTML entities
/K:bpcondense repeated blanks or punctuation characters
/NNot really; list items but don’t rename them
/N:flagsdisable features; flags may include:
     E: don’t display error messages
     F: don’t fix name collisions
     J: don’t recurse into junctions (only useful with /S)
     P: don’t decode %XX hexadecimal pairs
     S: don’t display summaries
/PPrompt before each
/Q:from-listlist of characters to replace
/R:to-listreplacement characters; use with /Q
/Srecurse into Subdirectories
/Ureplace high-order Unicode characters with underscores
filespecwildcard mask to match problematic files

This command expects one or more filespecs specifying the file(s) to be renamed. Use wildcards to match the difficult characters. Note that you do not supply a “new” or replacement filename — the plugin generates replacement filenames on its own. These new names can then be changed using the regular REN command, if desired.

The following characters are currently considered “troublesome” by default: control characters (0x01—0x1f and 0x80—0x9f), percent signs (%), carets (^), grave accents / back quotes (`), double quotes ("), and non-breaking spaces (0xa0). This list may change in future releases, and several of FixName’s options allow you to add other characters.

Trailing spaces and periods at the end of a filename are also problematic, and FixNames will attempt to remove them.

If a filename contains a percent sign followed by two hexadecimal digits, the trio is treated as an encoded character; the percent sign and two following letters or digits will be replaced with a single character. You can disable this replacement with /NP. If /E is specified, the same replacement is also performed for an equals sign followed by two hex digits.


/Q:from-list and /R:to-list allow you to specify lists of character replacements. If a filename contains a character in from-list, that character will be replaced with the character at the same position in to-list. If there is no matching character (because from-list is longer than to-list, or because you didn’t give a /R:), then the character will simply be dropped.

fixnames /q:@#$ /r:__ *

rem   Replaces at-signs and number signs with underscores.
rem   Dollar signs will just be deleted.


If you specify /H, FixNames will decode any HTML entities in filenames. For example, a file named "File ©2022.txt" would be renamed to "File ©2022.txt". Both named and numeric entities are recognized. Note that if an entity names a troublesome or illegal character, that character will in turn be replaced.


/K causes FixNames to condense repeated blanks or punctuation marks. If you specify /K:B then any run of two or more whitespace characters will become a single space. If you use /K:P then a run of any punctuation mark repeated more than once will be replaced with a single character. /K with no suboptions will do both.


If you include /U, FixNames will replace any high-order Unicode characters (characters with a value greater than 0xFFFF) with underscores. If the filename contains any unpaired UTF-16 surrogate characters, these also will be replaced with underscores.


When renaming a file, FixNames will check whether a file with the same name already exists. If so, the new name will be modified by appending a number before the extension to avoid the name collision. /NF disables this feature; name collisions will cause an error message, and the offending file will not be renamed.

Startup Message:

This plugin displays an informational line when it initializes. The message will be suppressed in transient or pipe shells. You can disable it for all shells by defining an environment variable named NOLOADMSG, for example:

set /e /u noloadmsg=1

Status and Licensing:

Consider this beta software. It may well have issues. Try it at your own risk. If you find bugs, you can report them in the JP Software support forum.

FixNames is currently licensed only for testing purposes. I may make binaries and source code available under some free license once I consider it ready for use.

Download:

You can download the current version of the plugin from http://charlesdye.net/dl/fixnames.zip.