Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
atamo
- Posts: 15
- Joined: 17 May 2010 09:14
#1
Post
by atamo » 01 Apr 2011 07:52
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
-
dbenham
- Expert
- Posts: 2461
- Joined: 12 Feb 2011 21:02
- Location: United States (east coast)
#2
Post
by dbenham » 01 Apr 2011 14:43
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.
-
atamo
- Posts: 15
- Joined: 17 May 2010 09:14
#3
Post
by atamo » 05 Apr 2011 03:58
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