Welcome!

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

SignUp Now!

How to rename files with "("

Code:
[C:\z_NewAll\WAV_000]for %fn in ( [(]* ) ren /n "%fn" "%@right[-1,%fn]"
C:\z_NewAll\WAV_000\(B4D88~111121222222.WAV -> C:\z_NewAll\WAV_000\%@right[-1,%fn]
     1 file would be renamed
C:\z_NewAll\WAV_000\(B8A3C~1.WAV -> C:\z_NewAll\WAV_000\%@right[-1,%fn]
     1 file would be renamed
C:\z_NewAll\WAV_000\(BB695~1.WAV -> C:\z_NewAll\WAV_000\%@right[-1,%fn]
     1 file would be renamed
 
I dunno. It seems like it should work. But it doesn't.
Code:
v:\> ren /n "readjob.btm" "%@right[-1,readjob.btm]"
V:\readjob.btm -> V:\eadjob.btm
  1 file would be renamed

v:\> d (*
2014-07-26  21:39  0  (ab.txt

v:\> for %fn in ( [(]* ) echo "%@right[-1,%fn]"
"ab.txt"

v:\> for %fn in ( [(]* ) ren /n "%fn" "%@right[-1,%fn]"
V:\(ab.txt -> V:\%@right[-1,%fn]
  1 file would be renamed

v:\> for %fn in ( [(]* ) ren "%fn" "%@right[-1,%fn]"
V:\(ab.txt -> V:\%@right[-1,%fn]
  1 file renamed

v:\> d *@*
2014-07-26  21:39  0  %@right[-1,%fn]

DO won't even ECHO it.
Code:
v:\> do fn in [(]* ( echo "%fn" "%@right[-1,%fn]" )
"(ab.txt" "%@right[-1,%fn]"
 
It seems like the first reference to %fn is screwing up the parsing of the next argument.
Code:
v:\> d (*
2014-07-26  21:50  0  (ab.txt

v:\> do fn in [(]* ( echo "%@right[-1,foo]" )
"oo"

v:\> do fn in [(]* ( echo "%fn" "%@right[-1,foo]" )
"(ab.txt" "%@right[1,foo]"

v:\> for %fn in ( [(]* ) echo "%@right[-1,foo]"
"oo"

v:\> for %fn in ( [(]* ) echo "%fn" "%@right[-1,foo]"
"(ab.txt" "%@right[-1,foo]"
 
Thanks Vince. So then there is a problem with the current TCMD / TCC right? Or do I misunderstand your posts above?
 
It seems a problem to me ... but I can't imagine what's happening.

Here's a simpler manifestation.
Code:
v:\> set fn=(ab.txt

v:\> echo "%@right[-1,foo]"
"oo"

v:\> echo "%fn" "%@right[-1,foo]"
"(ab.txt" "%@right[-1,foo]"
That doesn't happen when the literal string is used.
Code:
v:\> echo "(ab.txt" "%@right[-1,foo]"
"(ab.txt" "oo"

I think it's looking for a ')' inside quotes. Why it doesn't evaluate the @RIGHT function anyway ... I dunno.
Code:
v:\> echo "%fn" ga)rbage "%@right[-1,foo]"
"(ab.txt" ga)rbage "%@right[-1,foo]"

v:\> echo "%fn" "ga)rbage" "%@right[-1,foo]"
"(ab.txt" "ga)rbage" "oo"
 
This gets around the difficulty (I don't know about other problems that might arise).
Code:
v:\> for %fn in ( [(]* ) ren /n %@quote[%fn] "%@right[-1,%fn]"
V:\(ab.txt -> V:\ab.txt
  1 file would be renamed

This seems to be OK also.
Code:
v:\> for %fn in ( [(]* ) ren /n %@quote[%fn] %@quote[%@right[-1,%fn]]
V:\(ab.txt -> V:\ab.txt
  1 file would be renamed
 
Heehee! I had put NOOP, _NOOP, and @NOOP in 4UTILS (mostly for kicks). But perhaps at least one of them is useful for protecting things from those very_hard_to_understand anomalies of the parser.
Code:
v:\> for %fn in ( [(]* ) ren /n %@noop["%fn"] "%@right[-1,%fn]"
V:\(ab.txt -> V:\ab.txt
  1 file would be renamed
 
It is peculiar. I'm still one TCC version back, and...

I start with:

abczzz.txt
defzzz.txt
(test1.tmp
(test2.tmp


Then, a small .btm file:

setlocal
do _thisfile in *.txt
echo original name: %_thisfile
set newname=%@replace[zzz,YYY,%_thisfile]
echo new name: %newname
echo ren %_thisfile %newname
echo.
enddo

:: the above succeeds

unset newname

do _thisfile in *.tmp
echo original name: %_thisfile
set newname=%@replace[(,,%_thisfile]
echo new name: %newname
echo ren "%_thisfile" %newname
echo.
enddo

:: the above fails

Result on-screen, with the "huh?" parts in boldface:

original name: abczzz.txt
new name: abcYYY.txt
ren abczzz.txt abcYYY.txt

original name: defzzz.txt
new name: defYYY.txt
ren defzzz.txt defYYY.txt

original name: (test1.tmp
new name: test1.tmp
ren "(test1.tmp" %newname

original name: (test2.tmp
new name: test2.tmp
ren "(test2.tmp" %newname


I didn't know which of the setdos commands might assist with this and tried "setdos /x-5" but it made no difference.
 
I'm lost. Why doesn't the third echo work (while the second and fourth one do work)?
Code:
v:\> set fn=(ab.txt

v:\> echo "%fn" ga)rbage "%@right[-1,foo]"
"(ab.txt" ga)rbage "%@right[-1,foo]"

v:\> echo "%fn" "ga)rbage" "%@right[-1,foo]"
"(ab.txt" "ga)rbage" "oo"

v:\> echo "%fn" "ga)rbage" "(%@right[-1,foo])"
"(ab.txt" "ga)rbage" "(%@right[-1,foo])"

v:\> echo "(%@right[-1,foo])"
"(oo)"
 
Heehee! I had put NOOP, _NOOP, and @NOOP in 4UTILS (mostly for kicks). But perhaps at least one of them is useful for protecting things from those very_hard_to_understand anomalies of the parser.
Code:
v:\> for %fn in ( [(]* ) ren /n %@noop["%fn"] "%@right[-1,%fn]"
V:\(ab.txt -> V:\ab.txt
  1 file would be renamed

I looked at the 4Utils.txt in in the ZIP located on the plugins page at JPSoft - didn't see any reference to noop...... ???
 
I haven't updated it in a while. It may be in a state of disarray because of experimental stuff. I'll check and, maybe, upload a new one one of these days. Any function that does essentially nothing will have the same effect.
Code:
v:\> for %fn in ( [(]* ) ren /n %@replace[(,(,"%fn"] "%@right[-1,%fn]"
V:\(ab.txt -> V:\ab.txt
  1 file would be renamed

v:\> for %fn in ( [(]* ) ren /n %@instr[0,100,"%fn"] "%@right[-1,%fn]"
V:\(ab.txt -> V:\ab.txt
  1 file would be renamed
 

Similar threads

Back
Top