Rename many files quickly on the command line through simple expressions with the free Swiss File Knife for Windows, Mac OS X and Linux.
sfk rename dirname "/fromtext/totext/" [to outdir]sfk rename -dir mydir -file .txt -pat "/fromtext/totext/"
flexible multi file rename using rename expressions.
handle with care.
- multi file rename may cause problems in folders which are
controlled by version control systems like cvs or svn,
or within workspaces of programs that keep file references,
like video editing software or IDE's.
- keep backups of original files in case that output
filenames are unexpected or cause conflicts.
to make things more safe, by default
- sfk rename runs on the given folder only, without sub folders.
use option -withsub to include sub folders.
- sfk rename runs in simulation mode, previewing changes without
modifying anything. add option -yes to apply changes.
syntax of /fromtext/totext/
rename expressions are a subset of simple expressions, supporting
an extra symbol '#' within totext. slash patterns are not enabled
by default but require an option -spat. instead of "/" around
/from/to/ any unique char can be used, like in _fromtext_totext_
within /fromtext/ you may use:* for any number of chars (0 or more)
? for exactly one character
[n chars] for exactly n characters
within /totext/ you may use:[part1] fill in part 1 extracted from name
[parts 1,3] fill in parts 1 and 3
[parts 1-3] fill in parts 1 to 3
#1 fill in part 1, same as [part1]
#10 fill in part 10
# without digits: fill in next part
#5## fill in parts 5,6,7
with option -spat only:\[ search or fill in the '[' character
\] \# * \? same for characters ] # * ?
\\ search or fill in the backslash '\'
to outdir after rename, move the file to folder outdir
which must be on the same partition.
-pat x to specify /from/to/ pattern after
long -dir ... -file ... parameters
-spat enable slash patterns like \xnn
-exact fromtext must match whole filename,
not just a part of it.
-verbose show part numbers within /from/ text
accent or umlaut characters in the search pattern
may have to be rewritten by wildcard "?" to match.
quoted multi line parameters are supported in scripts
using full trim. type "sfk script" for details.
aliasessfk rensub same as "sfk rename -withsub"
beware of Shell Command Characters.
to find or replace text patterns containing spaces or special
characters like <>|!&?* you must add quotes "" around parameters
or the shell environment will destroy your command. for example,
pattern /foo bar/other/ must be written like "/foo bar/other/"
within a .bat or .cmd file the percent % must be escaped like %%
even within quotes: sfk echo -spat "percent %% is a percent \x25"about example numbers with [brackets]
if you see  type "sfk cmd 1" for whole command in one line.
web referencehttp://stahlworks.com/sfk-renamemore in the SFK Book
the SFK Book contains a 60 page tutorial, including
rename examples with input and output filenames.
type "sfk book" for details.
examples: short syntax step by stepsfk rename mydir
list all files of mydir (nothing is changed)
sfk ren mydir "/-1540-*.mts/"
list files in mydir with "-1540-" in their
filename, followed by any characters, until .mts.
sfk will show an info text telling about the part
numbers the search mask (fromtext) is made of.
sfk ren mydir "/-1540-*.mts/[part1]News[part3]/"
same as above, but extended to change the wild-
card part "*" of a match to "News".
sfk ren mydir "/-1540-*.mts/#News#3/"
same as above, but shorter to type. "#" without
a number takes part1, #3 takes part 3.
sfk ren mydir "/-1540-*.mts/#News#3/" to news
after rename move the file to folder "news".
finally add -yes to apply filename changes.
examples: flexible syntax step by stepsfk rename -dir mydir -file chan
list files of mydir having "chan" in their name
sfk ren -dir mydir -file chan -pat "/-1540-*.mts/"
list chan files in mydir with "-1540-" in their
filename, followed by any characters, until .mts
sfk ren -dir mydir -file chan -pat "/-1540-*.mts/#News#3/"
within filenames of mydir containing parts
-1540-, then anything, then .mts, like in:
change the second part "*" into "News":
further examplessfk rename . /.mts/.mpg/
change all .mts to .mpg in current folder
sfk ren -dir mydir -file .txt -pat "/foo/bar/"
replace foo by bar in all .txt filenames within mydir
sfk ren -dir mydir -file "*-????2015-"-pat "/-[2 chars][2 chars][4 chars]-[4 chars]-*./-[parts 4,2,3]-[parts 6-9]/"
in folder mydir change date string in files like: 
to a format with year first:
sfk ren -dir mydir -file "*-????2015-"-pat "/-[2 chars][2 chars][4 chars]-[4 chars]-*./-#4#2#-#6###/"
same as above, only shorter. #6### means to take
part 6 and then the three following parts 7,8,9.