FILTERFILES — Pass files through a text filter command.

Syntax:
FILTERFILES /B:.ext /C /J /N /P /Q /S /UTF8 /UTF16 filespec… : command args…

/B:.extextension for backups; the default is .original
/Cdo not abort if the command exits with errorlevel 3
/Nnot really
/Ndisable features
/Jredirect input
/Pprompt for each file
/Qquietly
/Ssearch in subdirectories for matching files
/UTF8redirect output as UTF-8
/UTF16redirect output as UTF-16
Range options are also supported.
filespec…the files to process; at least one filespec is required
commanda filter command which writes to stdout

At least one filespec is required. Anything after the first unquoted colon is the command to execute; this also is required.

Matching files will be renamed with a .original extension, or as per /B. Then the specified command will be called, passing the new filename on its command line after any args, and with its output redirected to the new filename.

This command only supports local files. CLIP:, URLs, standard input, and so on are not supported.


/N by itself prevents FILTERFILES from doing anything. Matching files will be displayed but not renamed, and the command will not be executed.

/N with suboptions disables features:

/NCdisable highlight
/NDdo not search into hidden directories; only useful with /S
/NFsuppress the file-not-found error
/NJdo not search into junctions; only useful with /S
/NZdo not search into system directories; only useful with /S

You can combine these, e.g. /NDJ.


/P causes FILTERFILES to prompt before processing each file. You can press:

Yto filter the file
N or Escto skip the file
Ato stop prompting and filter all remaining files
Qto exit immediately

/UTF8 and /UTF16 let you set the output encoding. They call OPTION //UnicodeOutput= and OPTION //UTF8Output= before processing files, and then restore the original settings before FILTERFILES exits. Note that //UTF8Output does not actually work in TCC/LE.


By default, FILTERFILES passes each original filename to the command on its command line:

filtercmd "file.original" > "file.txt"

If you specify /J, it will use input redirection instead:

filtercmd < "file.original" > "file.txt"


FILTERFILES is mainly intended for use with the filters in this plugin: DEDUP, DEGAS, DEHTML, WRAP, and so on. But you can use it with any command that either accepts a filename on its command line or reads from standard input, and that writes text to standard output.


rem   Convert all .TXT file in the current directory to Pig Latin:

filterfiles *.txt : oink


rem   Add line numbers to MyFile.txt:

filterfiles myfile.txt : type /L