giordano
giordano

Reputation: 3162

TCL onliner: replace string in filename

Is there a way to replace strings in filenames with oneliner using TCL. For example, with perl it would be:

files:

testA1.txt
testA2.txt
testA3.txt

Oneliner

perl -e "while(<test*>) {($new=$_) =~ s/A/B/; rename $_, $new}"

Files

testB1.txt
testB2.txt
testB3.txt

In generally, is TCL appropriate for oneliners? I didn't find in the net oneliners for TCL as I found for Perl and Powershell.

OS: Windows 7

Upvotes: 0

Views: 336

Answers (1)

Jerry
Jerry

Reputation: 71598

The simplest I can think of would be this:

foreach f [glob test*] {file rename $f [string map {A B} $f]}

Like in any language though, one liners are generally for quick and dirty things or for fun. Not something you'd find in proper code.

Upvotes: 1

Related Questions