Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / VB.NET / October 2007

Tip: Looking for answers? Try searching our database.

Getting Only Non-Hidded and Non-System Directories

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Nathan Sokalski - 16 Oct 2007 00:53 GMT
I am getting the list of subdirectories from a specified directory using
System.IO.Directory.GetDirectories(), and would like to get only
subdirectories that are not hidden or system directories. I did not notice
any way to do this using System.IO.Directory.GetDirectories(). Is there some
other function that I can use, or is there some way to determine whether a
directory is hidden or system? Thanks.
Signature

Nathan Sokalski
njsokalski@hotmail.com
http://www.nathansokalski.com/

Tom Shelton - 16 Oct 2007 01:16 GMT
> I am getting the list of subdirectories from a specified directory using
> System.IO.Directory.GetDirectories(), and would like to get only
[quoted text clipped - 5 lines]
> Nathan Sokalski
> njsokal...@hotmail.comhttp://www.nathansokalski.com/

You can use System.IO.DirectoryInfo.GetDirectories to return an array
of DirectoryInfo objects.  This object has an Attributes property,
which you can check to see if the system or hidden attributes are
applied.

--
Tom Shelton
Nathan Sokalski - 16 Oct 2007 12:47 GMT
Could you show me an example of how I test for these attributes? It seems
like the Attributes property has an enumeration containing Hidden and
System, but I am having trouble testing whether they are true for the
current DirectoryInfo. Thanks.

>> I am getting the list of subdirectories from a specified directory using
>> System.IO.Directory.GetDirectories(), and would like to get only
[quoted text clipped - 16 lines]
> --
> Tom Shelton
Tom Shelton - 17 Oct 2007 06:29 GMT
> Could you show me an example of how I test for these attributes? It seems
> like the Attributes property has an enumeration containing Hidden and
[quoted text clipped - 23 lines]
>
> - Show quoted text -

Nathan,

Those attributes are flag attributes - so a simple bitwise and will
tell you if they have the attribute:

Option Strict On
Option Explicit On

Imports System
Imports System.IO

Module Module1

   Sub Main()
       Dim rootInfo As DirectoryInfo = New DirectoryInfo("c:\")
       For Each d As DirectoryInfo In rootInfo.GetDirectories()

           If (d.Attributes And FileAttributes.System) <>
FileAttributes.System Then
               Console.WriteLine(d.Name)
           End If
       Next
   End Sub

End Module

HTH,

--
Tom Shelton

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.