Page 1 of 1
RENAME using redirection operators......
Posted: 01 Apr 2011 07:52
by atamo
Hy
I want to rename a file with a name from a text file, e.g.
Code: Select all
ren old.rar < newname.txt
where newname.txt contain a single line: new.rar
I get syntax error
if I use
Code: Select all
for /f %i in (c:\newname.txt) do ren c:\old.rar %i
work fine ... but why can't I use redirection operators, Which is the good syntax
Re: RENAME using redirection operators......
Posted: 01 Apr 2011 14:43
by dbenham
Because command (program) command line arguments are not the same thing as command (program) input (also known as stdin, or standard input).
From an English language perspective, yes they are both forms of input to the program. But from a programming standpoint they are very different.
The < operator is providing data for standard input, but the ren command does not make use of the input. It requires two arguments, source and destination.
A few commands allow such operations, but they are not the norm. For example:
findstr xyz file.txt
and
findstr xyz < file.txt
will yield the same results, but that is only because the developer of the command went to extra effort to add that capability. It does not happen automatically.
Posted: 05 Apr 2011 03:58
by atamo
Thank's the meticulous explain
dbenham wrote:It requires two arguments, source and destination.
unfortunately the next code also don't work:
Code: Select all
ren < newname.txt
where newname.txt contain a single line with two parameters: old.rar new.rar