Welcome!

By registering with us, you'll be able to discuss, share and exchange private messages with other members of our community.

SignUp Now!

WAD Weird REN bug

samintz

Scott Mintz
May
1,580
28
I ran into an issue the other day with REN. It seems the issue exists in V16 as well as V17.

I had a handful of files named ECCTOOL* and I wanted to rename then to FKTOOL*.

The rename seems to take place in-place and characters are left over or removed. Since FK has 1 fewer letter than ECC the resulting renamed file has an extra character.

ECCTool ==> FKTooll

When I went to rename them back, I used REN FK* ECC* and it replaced FKT with ECC resulting in files named ECCool* instead of ECCTool*.
 
It goes back farther that that. It's probably WAD.
Code:
v:\> ver

4NT  8.02.106  Windows Vista [Version 6.1.7601]

v:\> touch /c abcdefgh
2014-11-13 11:16:48.199  V:\abcdefgh

v:\> ren ab* xyz*
V:\abcdefgh -> V:\xyzdefgh
  1 file renamed

v:\> ren xyz* ab**
V:\xyzdefgh -> V:\abzdefgh
  1 file renamed
 
I wrote a BTM script that I call REN-SUB, to handle this. Here is the syntax message it produces when invoked with too few arguments:

TCC(17.00.52): C:\commands\bat>ren_sub

This program renames files by substituting one string for another the
first time it occurs in the name. The syntax is as follows:

SYNTAX: REN_SUB filespec old_string new_string [/n]

For example,

REN_SUB abc13-def.txt 13 2013

would result in the file being renamed to abc2013-def.txt

If there is an optional fourth argument, /n, then the command only echos
the rename commands that would be performed.


Here is the script contents (suggestions for improvements are most welcome!):

Code:
@echo off

if %# LT 3 goto syntax

set testflag=0

if "%4" EQ "/n" set testflag=1

set strlen=%@len[%2]

do file in /a:-d-h %1

  set startpos=%@index[%file,%2]
  if %startpos EQ -1 iterate

  echo.
  set continuepos=%@eval[%startpos + %strlen]
  set newname=%@instr[0,%startpos,%file]%3%@instr[%continuepos,%file]

  iff %testflag EQ 0 then
  *ren %file %newname
  else
  echo `  `*ren %file %newname
  endiff

enddo

quit

:syntax

text

  This program renames files by substituting one string for another the
  first time it occurs in the name. The syntax is as follows:

endtext

echo `  `SYNTAX: REN_SUB filespec old_string new_string [/n]

text

  For example,

  REN_SUB abc13-def.txt 13 2013

  would result in the file being renamed to abc2013-def.txt

  If there is an optional fourth argument, /n, then the command only echos
  the rename commands that would be performed.
endtext

quit
 
I tried the following rename command and got mixed results. It basically just renamed one file.

Code:
11/12/2014  16:12           8,192  FKtool.exe
11/12/2014  16:12             381  FKtool.exe.intermediate.manifest
11/12/2014  19:09              85  FKtool.lastbuildstate
11/12/2014  19:09          72,442  FKtool.obj
11/12/2014  16:12         273,408  FKtool.pdb
11/11/2014  20:45             713  FKtool.vcxprojResolveAssemblyReference.cache
11/11/2014  20:45               0  FKtool.write.1.tlog
11/12/2014  19:09           9,728  FKtool64.exe
11/12/2014  19:09             381  FKtool64.exe.intermediate.manifest
11/12/2014  19:09         265,216  FKtool64.pdb

ren ::FK(.*) ::ECC\1

11/11/2014  20:45             713  ECCtool.vcxprojResolveAssemblyReference.cache
11/12/2014  16:12           8,192  FKtool.exe
11/12/2014  16:12             381  FKtool.exe.intermediate.manifest
11/12/2014  19:09              85  FKtool.lastbuildstate
11/12/2014  19:09          72,442  FKtool.obj
11/12/2014  16:12         273,408  FKtool.pdb
11/11/2014  20:45               0  FKtool.write.1.tlog
11/12/2014  19:09           9,728  FKtool64.exe
11/12/2014  19:09             381  FKtool64.exe.intermediate.manifest
11/12/2014  19:09         265,216  FKtool64.pdb
 
Just to clarify, that rename command says it renamed 9 files. But it actually only renamed 1.

It works correctly in V16
 

Similar threads

Back
Top