How to tell if a directory/file is a system directory/file??

sj1187534

Well-known member
Joined
Jun 10, 2003
Messages
108
Location
Dallas, Houston, etc.etc.
Hi...The title pretty much says what I am trying to do. This is because when I am populating a treeview with all the folders from the system, it is saying that the directory F:\System Volume Information cannot be accessed because it is a system file. It doestnt exactly say the reason but thats what I am thinking. The wierd thing is C# is not having this problem. It is with VB.NET alone.

Any ideas?

SJ
 
If you work with the Directory.GetDirectories class or similar then you dont need to worry about checking if its a file or directory.
 
Hi Jabe, RIght now, this is how I am trying to check it, but it is returning true for every directory!!
---------------------------------------------------------------------
Private Function IsSystemFile(ByRef dir As DirectoryInfo) As Boolean
If dir.Attributes().System = FileAttributes.System Then
Return True
Else
Return False
End If
End Function
---------------------------------------------------------------------
Please let me know if there is any other way to check that.


And mutant.....I am using the Directory.GetDirectories class to get the list of directories. This is what it is saying when I run the application:
--------------------------------------------------------------------------
Access to path f:\\System Volume Information is denied
--------------------------------------------------------------------------
I am not getting this message for the C and D drives which are being checked before the F-drive according to my algorithm.
Any ideas??

Hi PlausiblyDamp...I understand that it is the permission problem. But when we r running this application on the web, we cant possibly do anything about the permissions of the users system directories..istnt it???

Thanks for your time guys......

SJ
 
sj1187534,

I dont have VS.NET handy right now but this is worth a shot:

[VB]
Private Function IsSystemFile(ByRef dir As DirectoryInfo) As Boolean
Return (dir.Attributes And FileAttributes.System) > 0
End Function
[/VB]
 
Hi Jade...What you said worked on my system without any problem. Now, I have a new problem. The same project is returning the same error for a different folder in a different system. Is this problem system specific??? I heard that if we use DirectoryInfo.GetDirectories() should not worry about this. I am using the same but I dont know why I am getting this error.

The new error is showing that access is denied to C:\\Config.msi.

Ideas?

SJ
 
Sounds like the security features of Windows are kicking in... is this an NTFS partition?

I think the best way to do it is to simply place your code inside a Try....Catch block and bypass the error.
Code:
Try
  do your check here
Catch e As Exception
  System.Diagnostics.Debug.WriteLine("Error encountered: " & e.Message)
End Try
 
Back
Top