Odd behavior in a command prompt window

J

Jonathan Sachs

I wonder if anyone can explain why Windows XP's command line processor
did something very odd to me just now.

I had a directory which contained many files with the extension .html,
which were _not_ HTML files, and corresponding files with the
extension .html.en (for "English"), which were.

I entered the following commands to delete the HTML files and rename
the HTML.EN files:

del *.html
ren *.html.en *.html

I moved on without checking my work, but later I noticed that the
original .HTML files were still there, and the .html.en files had been
given the extension .html.html!

Accordingly I entered the commands

ren *.html *.hhhh
del *.html

to preserve the "real" HTML files and delete the fakes. That worked
as expected. Then I entered the command

ren *.hhhh *.html

to rename the real files, and I ended up with a bunch of .html.html
files again!

Why did it do that?
 
L

LVTravel

Jonathan Sachs said:
I wonder if anyone can explain why Windows XP's command line processor
did something very odd to me just now.

I had a directory which contained many files with the extension .html,
which were _not_ HTML files, and corresponding files with the
extension .html.en (for "English"), which were.

I entered the following commands to delete the HTML files and rename
the HTML.EN files:

del *.html
ren *.html.en *.html

I moved on without checking my work, but later I noticed that the
original .HTML files were still there, and the .html.en files had been
given the extension .html.html!

Accordingly I entered the commands

ren *.html *.hhhh
del *.html

to preserve the "real" HTML files and delete the fakes. That worked
as expected. Then I entered the command

ren *.hhhh *.html

to rename the real files, and I ended up with a bunch of .html.html
files again!

Why did it do that?

The reason that the original html.en renamed html.html is that the rename
command will rename anything after the last period (.en) to the desired
rename which was .html so you got .html.html (the first html was "part of
the file name" and not the extension.

The reason for the last .html.html is the same reason as the first. Since
you got rid of the bad original .html files you now simply need to get rid
of the last .html on the filenames. Not really as easy as it sounds,
correct. Actually it is pretty easy. Here's how it should go:

type REN *.HTML.HTML *. (note the period behind the last *) This
should remove the last html from each filename.

Let us know what happens.
 
J

Jonathan Sachs

type REN *.HTML.HTML *. (note the period behind the last *) This
should remove the last html from each filename.

Let us know what happens.

Thank you, that did work. It doesn't make any sense to me, though. I
have seen DOS/Windows commands ignore wildcard characters that they
didn't know how to process, but this is the first time I've seen a
command go and do something completely different that was requested.
I am trying to abstract a logical rule that will explain this result,
and I can't.

I guess I'd better find a kit of UNIX-style file management utilities
before the next time I need to do something like this.
 
L

LVTravel

Jonathan Sachs said:
Thank you, that did work. It doesn't make any sense to me, though. I
have seen DOS/Windows commands ignore wildcard characters that they
didn't know how to process, but this is the first time I've seen a
command go and do something completely different that was requested.
I am trying to abstract a logical rule that will explain this result,
and I can't.

I guess I'd better find a kit of UNIX-style file management utilities
before the next time I need to do something like this.


The DOS command did exactly what you told it to do. Remember that the
current REN command is only slightly "smarter" than the REN command that
only dealt with 8 character filename X3 character extensions under DOS. In
true DOS you could only have one period in a filename and that denoted the
start of the extension. With the slightly smarter version, you can have
more than one period (as well as spaces) and the extension can be longer
than 3 characters but the extension is still denoted by the last period that
is encountered when the filename is parsed by the command. Therefore the
filename was "This is the filename.html" while the extension was "en" before
the original REN was done. After the original REN was done, the "en" was
renamed "html" so what you then had was the original filename "This is the
filename.html" followed by the renamed extension of "html".

The reason that my REN command worked was that the *. without anything
behind it deletes the extension and without the extension the final period
is useless so the REN command deletes it also.

Hope this explains it so you can figure it out. If any additional
information or help is needed, please don't hesitate to ask.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top