Discussion:
Rename DOS File
(too old to reply)
b***@gmail.com
2007-10-31 17:20:27 UTC
Permalink
Hello,

Is it possible to use the rename command to rename a *.ITF file with
the filename of a TXT file in the same directory. For example
Directory 1 contains:


DEAL1.ITF
BRETT.TXT
DEAL1.LOG


Is it possible to rename DEAL1.LOG to BRETT.LOG (the same name of the
TXT file). The TXT file will be a different name each time,
therefore
it needs to be some kind of variable rename i.e. always rename
the .LOG file to that of the .TXT filename.


Thanks,


Brett
Herbert Kleebauer
2007-10-31 18:09:02 UTC
Permalink
Post by b***@gmail.com
Hello,
Is it possible to use the rename command to rename a *.ITF file with
the filename of a TXT file in the same directory. For example
DEAL1.ITF
BRETT.TXT
DEAL1.LOG
Is it possible to rename DEAL1.LOG to BRETT.LOG (the same name of the
TXT file). The TXT file will be a different name each time,
therefore
it needs to be some kind of variable rename i.e. always rename
the .LOG file to that of the .TXT filename.
for %%i in (*.txt) do set n=%%~ni
ren *.log %n%.log
b***@gmail.com
2007-10-31 18:20:59 UTC
Permalink
Post by Herbert Kleebauer
Post by b***@gmail.com
Hello,
Is it possible to use the rename command to rename a *.ITF file with
the filename of a TXT file in the same directory. For example
DEAL1.ITF
BRETT.TXT
DEAL1.LOG
Is it possible to rename DEAL1.LOG to BRETT.LOG (the same name of the
TXT file). The TXT file will be a different name each time,
therefore
it needs to be some kind of variable rename i.e. always rename
the .LOG file to that of the .TXT filename.
for %%i in (*.txt) do set n=%%~ni
ren *.log %n%.log- Hide quoted text -
- Show quoted text -
Hello,

Thank you for your help.

I receive the error %%i was unexpected at this time.

Thanks,
Brett
Herbert Kleebauer
2007-10-31 18:47:12 UTC
Permalink
Post by b***@gmail.com
Post by Herbert Kleebauer
Post by b***@gmail.com
Hello,
Is it possible to use the rename command to rename a *.ITF file with
the filename of a TXT file in the same directory. For example
DEAL1.ITF
BRETT.TXT
DEAL1.LOG
Is it possible to rename DEAL1.LOG to BRETT.LOG (the same name of the
TXT file). The TXT file will be a different name each time,
therefore
it needs to be some kind of variable rename i.e. always rename
the .LOG file to that of the .TXT filename.
for %%i in (*.txt) do set n=%%~ni
ren *.log %n%.log
- Show quoted text -
Hello,
Thank you for your help.
I receive the error %%i was unexpected at this time.
The above two lines are for a batch file. If you directly enter
them in the command line you must only use one %:

for %i in (*.txt) do set n=%~ni
ren *.log %n%.log

And this only works in W2k/XP not in DOS6/Win9x.
Phred
2007-11-01 09:53:48 UTC
Permalink
Post by Herbert Kleebauer
Post by Herbert Kleebauer
Post by b***@gmail.com
Is it possible to use the rename command to rename a *.ITF file with
the filename of a TXT file in the same directory. For example
DEAL1.ITF
BRETT.TXT
DEAL1.LOG
Is it possible to rename DEAL1.LOG to BRETT.LOG (the same name of the
TXT file). The TXT file will be a different name each time, therefore
it needs to be some kind of variable rename i.e. always rename
the .LOG file to that of the .TXT filename.
for %%i in (*.txt) do set n=%%~ni
ren *.log %n%.log
[...]
Post by Herbert Kleebauer
The above two lines are for a batch file. If you directly enter
for %i in (*.txt) do set n=%~ni
ren *.log %n%.log
And this only works in W2k/XP not in DOS6/Win9x.
Is that just because the wildcard doesn't work in the for ... do?

Cheers, Phred.
--
***@THISyahoo.com.INVALID
foxidrive
2007-11-01 10:56:49 UTC
Permalink
Post by Phred
Post by Herbert Kleebauer
Post by Herbert Kleebauer
Post by b***@gmail.com
DEAL1.ITF
BRETT.TXT
DEAL1.LOG
Is it possible to rename DEAL1.LOG to BRETT.LOG (the same name of the
TXT file). The TXT file will be a different name each time, therefore
it needs to be some kind of variable rename i.e. always rename
the .LOG file to that of the .TXT filename.
for %%i in (*.txt) do set n=%%~ni
ren *.log %n%.log
And this only works in W2k/XP not in DOS6/Win9x.
Is that just because the wildcard doesn't work in the for ... do?
The %%~ni construct does not work in DOS6/Win9x

What OS do you need it to work on?
Are long filenames a possibility or not?
Phred
2007-11-01 13:38:30 UTC
Permalink
Post by foxidrive
Post by Phred
Post by Herbert Kleebauer
Post by Herbert Kleebauer
Post by b***@gmail.com
DEAL1.ITF
BRETT.TXT
DEAL1.LOG
Is it possible to rename DEAL1.LOG to BRETT.LOG (the same name of the
TXT file). The TXT file will be a different name each time, therefore
it needs to be some kind of variable rename i.e. always rename
the .LOG file to that of the .TXT filename.
for %%i in (*.txt) do set n=%%~ni
ren *.log %n%.log
And this only works in W2k/XP not in DOS6/Win9x.
Is that just because the wildcard doesn't work in the for ... do?
The %%~ni construct does not work in DOS6/Win9x
What OS do you need it to work on?
Are long filenames a possibility or not?
G'day Foxi,

Thanks for your response.

I sometimes use "for ... do" constructs in CLI mode in Windows ME, but
AFAICR you can't use e.g.

FOR %a in (*.txt) do PRINT %a

so I was just wondering if that was the problem above.

But, now that I've had my dinner and three glasses of a nice red, I
note that I previously missed the implications of that "set n=%%~ni"
and, even with the clarity of alcohol-inspired thought processes, I'm
damned if I can see what that achieves anyway! 8-)

Please feel free to enlighten me. I will be very interested to know
what that bit does.

Cheers, Phred.
--
***@THISyahoo.com.INVALID
foxidrive
2007-11-01 15:02:00 UTC
Permalink
Post by Phred
Post by foxidrive
The %%~ni construct does not work in DOS6/Win9x
FOR %a in (*.txt) do PRINT %a
That should work, but you may need to use the start command with the /wait
option so multiple print jobs aren't spawned immediately.
Post by Phred
But, now that I've had my dinner and three glasses of a nice red, I
note that I previously missed the implications of that "set n=%%~ni"
and, even with the clarity of alcohol-inspired thought processes, I'm
damned if I can see what that achieves anyway! 8-)
Please feel free to enlighten me. I will be very interested to know
what that bit does.
Phred, under Windows XP the help has this to say:

===[screen capture]===
In addition, substitution of FOR variable references has been enhanced.
You can now use the following optional syntax:

%~I - expands %I removing any surrounding quotes (")
%~fI - expands %I to a fully qualified path name
%~dI - expands %I to a drive letter only
%~pI - expands %I to a path only
%~nI - expands %I to a file name only
%~xI - expands %I to a file extension only
%~sI - expanded path contains short names only
%~aI - expands %I to file attributes of file
%~tI - expands %I to date/time of file
%~zI - expands %I to size of file
%~$PATH:I - searches the directories listed in the PATH
environment variable and expands %I to the
fully qualified name of the first one found.
If the environment variable name is not
defined or the file is not found by the
search, then this modifier expands to the
empty string

The modifiers can be combined to get compound results:
===[screen capture]===

So %%~na resolves to the filename portion of the variable, excluding the
extension.
Richard Bonner
2007-11-01 14:45:25 UTC
Permalink
Post by foxidrive
Post by Herbert Kleebauer
Post by b***@gmail.com
DEAL1.ITF
BRETT.TXT
DEAL1.LOG
Is it possible to rename DEAL1.LOG to BRETT.LOG (the same name of the
TXT file). The TXT file will be a different name each time
for %%i in (*.txt) do set n=%%~ni
ren *.log %n%.log
The %%~ni construct does not work in DOS6/Win9x
*** Phred: For DOS systems, try 4DOS or XSET to achieve what you want.

One or more 4DOS and XSET links can be found in my "DOS Websites"
Directory at:

http://www.chebucto.ca/~ak621/DOS/Websites.html


Richard
Jim Langston
2007-11-06 07:08:41 UTC
Permalink
Post by Richard Bonner
Post by foxidrive
Post by Herbert Kleebauer
Post by b***@gmail.com
DEAL1.ITF
BRETT.TXT
DEAL1.LOG
Is it possible to rename DEAL1.LOG to BRETT.LOG (the same name of the
TXT file). The TXT file will be a different name each time
for %%i in (*.txt) do set n=%%~ni
ren *.log %n%.log
The %%~ni construct does not work in DOS6/Win9x
*** Phred: For DOS systems, try 4DOS or XSET to achieve what you want.
One or more 4DOS and XSET links can be found in my "DOS Websites"
http://www.chebucto.ca/~ak621/DOS/Websites.html
Why all the complicated shenanigans?

del *.LOG
ren *.ITF *.LOG
foxidrive
2007-11-06 07:54:24 UTC
Permalink
Post by Jim Langston
Post by b***@gmail.com
DEAL1.ITF
BRETT.TXT
DEAL1.LOG
Is it possible to rename DEAL1.LOG to BRETT.LOG (the same name of the
TXT file). The TXT file will be a different name each time
Why all the complicated shenanigans?
del *.LOG
ren *.ITF *.LOG
Read the requirement again.

Continue reading on narkive:
Loading...