DirectoryInfo.Create "succeeds" even if a same name file exists

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello all.

Is there any way to report bugs in the .NET framework?

I've found that both DirectoryInfo.Create and Directory.CreateDirectory
"succeed" even if a file with the same name already exists. No directory is
actually created (thank God, so the file remains in tact), but neither call
throws an exception (also, Directory.CreateDirectory returns a nonNull
DirectoryInfo). So one doesn't know that the directory creation failed until
one later calls some other method on the DirectoryInfo which will then throw
an exception.

Anyway, I'm trying to find a way to report this as a bug. Anyone know how
to do that?
 
Why is that behavior of DirectoryInfo.Create a bug? The documentation
clearly says that if the directory already exists it "does nothing". It also
says you'll get an IOException if it tries to create the directory and
fails, so your scenario of getting the error later won't occur (unless of
course it's not throwing the exception when it can't create the directory,
and that would be a bug).
 
Directory and file are different thing, you can have a file with the same
name as the directory where the file is. This has been always like this
since DOS. Why do you think it is a bug, or why .NET should not do this?
 
The documentation of DirectoryInfo.Create says that an IOException should be
thrown if the directory can't be created. But in my scenario (in which the
directory can't be created because a file with the same name already exists)
no exception is thrown at all. That's the bug.

(The documentation for Directory.CreateDirectory is a bit more convoluted
than that of DirectoryInfo.Create, and it's not clear what exception should
be thrown when calling Directory.CreateDirectory in my scenario, but I
imagine that an IOException would suffice. ;) As it stands now,
Directory.CreateDirectory, like DirectoryInfo.Create, throws no exception in
my scenario.)

Phil Wilson said:
Why is that behavior of DirectoryInfo.Create a bug? The documentation
clearly says that if the directory already exists it "does nothing". It also
says you'll get an IOException if it tries to create the directory and
fails, so your scenario of getting the error later won't occur (unless of
course it's not throwing the exception when it can't create the directory,
and that would be a bug).
--
Phil Wilson
[Microsoft MVP-Windows Installer]
Pepe Smythe said:
Hello all.

Is there any way to report bugs in the .NET framework?

I've found that both DirectoryInfo.Create and Directory.CreateDirectory
"succeed" even if a file with the same name already exists. No directory
is
actually created (thank God, so the file remains in tact), but neither
call
throws an exception (also, Directory.CreateDirectory returns a nonNull
DirectoryInfo). So one doesn't know that the directory creation failed
until
one later calls some other method on the DirectoryInfo which will then
throw
an exception.

Anyway, I'm trying to find a way to report this as a bug. Anyone know how
to do that?
 
You can't have a directory and file with the same name (within the same
parent directory). In a command shell, if you try to do "mkdir foo" and a
file with the name "foo" already exists, you get the "A subdirectory or file
foo already exists" error.

And calling DirectoryInfo.Create to create a directory with the same name as
that of an already existing file does not create a directory. So the call
fails, as it should, but it throws no exception (which is why I put
"succeeds" in quotes, when I said that the call "succeeds"; it actually
fails, but gives no indication of such). This is my complaint.
 
Hello,

Based on your description it looks like that .NET tried to find a
file/directory of that name and if it finds one, it does not create
directory, because file with same name is already there, but to me they have
forgotten to check file vs. directory. IMO, this is a bug.

If someone is creating a directory, .NET should test if a directory already
exists. If it does, then it's OK. If there is a file with that name,
IOException should be thrown.

JMu
 
Back
Top