FileInfo.Attributes value 294

  • Thread starter =?iso-8859-1?Q?Eivind_Gussi=E5s_L=F8kseth?=
  • Start date
?

=?iso-8859-1?Q?Eivind_Gussi=E5s_L=F8kseth?=

Hi!

I'm having trouble executing the FileSystem.CopyFile method because of some
strange behaviour of FileInfo.

The problem occurs when using the constructor of the FileInfo class. I pass
a filename of a file that doesn't exist, but when I check if the file exists
right after creating the FileInfo object, Exists returns True.

Dim vDestinationFile As New FileInfo(vDestinationFileName) ' No file with
this name exists

If vDestinationFile.Exists Then ' This is True, even if the file dosn't
exists on the given location.
....

So when I later try to call FileSystem.CopyFile(vSourceFile.FullName,
vDestinationFile.FullName, True) I get an UnauthorizedAccessException with
message: Access to the path
'C:\Users\Eivind.PROFVET\Documents\TranslationJunk\Clinic\TestTranslationForm.no.resx'
is denied.

I shouldn't have executed this method in the first place, because the True
parameter means that the file vDestionationFile.FullName should be replaced,
but it doesn't actually exist on the harddrive.

When debugging this strange behaviour, I found that
vDestinationFile.Attributes returns value 294. When I look at the
FileAttributes enum, I find that this means the file has the following
attributes:
- Temporary (value 256)
- Archive (value 32)
- System (value 4)
- Hidden (value 2)

These values added gives 294. So my question is: Why does .NET create this
file with those attributes when I use the constructor of FileInfo? I've
never experienced this problem before, even though I've been using the
FileInfo constructor a lot lately. I'm running this program on a Vista 32bit
machine.
 
?

=?iso-8859-1?Q?Eivind_Gussi=E5s_L=F8kseth?=

I've researched the problem a bit more, and here is what I've found:

I've created another .NET application that only instantiates a FileInfo
object and checks the Attributes and Exists properties. When I do this on
C:\Users\Eivind.PROFVET\Documents\test.txt, it works like expected, and
Exists property returns False. When I do the same for test.txt in the same
folder as I try to create the problem file, this also works like expected,
and the Exists property returns False.

But when I do the same for the exact same file as the problem file, the same
thing happens in this little test program. Attributes is 294 and Exists is
True. But I still can't see the file on my harddrive. I've even used command
promt with DIR and DEL <filename>. But the file doesn't exist. I've turned
on "Show hidden files and system files", but still can't see the file.

So I decided to delete the whole folder. And guess what happened! I got a
Copy Folder dialog saying that "The ...TestTranslationForm.no.resx folder
does not exist. The file may have been moved or deleted. Do you want to
create it?". I answered yes, and saw that the file was created before it was
deleted again.

When I run my little test program now, everything works as expected.
Attributes is -1 and Exists is False. So I guess my problem is gone forever,
and I won't be able to reproduce it ever again.
 

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