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 / Managed C++ / November 2007

Tip: Looking for answers? Try searching our database.

Directory::GetDirectories returning non-existent directories

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Peteroid - 03 Nov 2007 05:21 GMT
Assuming you have the default directory settings, try this code:

String^ full_path = "c:\\Users\\Owner\\Documents" ;
array<String^>^ dir_list = Directory::GetDirectories( full_path ) ;

In my case, it returns all the directories as it should in dir_list, but it
also returns the following non-existent (hidden?) directories:

My Music
My Pictures
My Videos

If I try to Directory::GetFiles( ) on any of these directories it throws an
exception, but it will successfully return the files of those directories
which are visible or do exist.

If I do a 'search' for any directories with those names, they are not found.

I have a Windows Vista machine, and I'm programming in VS VC++ 2008 Express
(Beta 2) /cli pure.

What is going on here?
Doug Harrison [MVP] - 03 Nov 2007 05:48 GMT
>Assuming you have the default directory settings, try this code:
>
[quoted text clipped - 18 lines]
>
>What is going on here?

In a nutshell, they're junction points MS added to Vista to help existing
programs that did things the wrong way. This article explains all:

Junction Points and Backup Applications
http://msdn2.microsoft.com/en-us/library/bb756982.aspx
<q>
These junction points have file attributes of FILE_ATTRIBUTE_REPARSE_POINT
& FILE_ATTRIBUTE_SYSTEM and the ACL’s are set to “Everyone Deny Read”.
Applications must have permissions in order to call out and traverse a
specific path. However, enumerating the contents of these junction points
is not possible.
</q>

The article very helpfully lists all the junction points, including the
ones you encountered. Hopefully, there is a Directory::GetDirectories
overload that you can use to prevent it from returning these unwanted
junctions.

To examine the security attributes of these junction points, you'll have to
go to Folder Properties and disable the options that hide files. Then
you'll be able to see them in Documents, as well as several in the root of
your profile folder.

Signature

Doug Harrison
Visual C++ MVP

Peteroid - 03 Nov 2007 14:29 GMT
Thank you, Doug!

I haven't found a version of GetDirectories that doesn't return junction
points. So I screen out junction points by doing a 'GetFiles( )' on it
within a try-catch and screen out those that get caught.

But I do think a version of GetDirectories that doesn't report junction
points is really something MS should include. Any solution that requires
try-catch feels like a 'hack' to me.

>>Assuming you have the default directory settings, try this code:
>>
[quoted text clipped - 46 lines]
> you'll be able to see them in Documents, as well as several in the root of
> your profile folder.
Doug Harrison [MVP] - 03 Nov 2007 17:19 GMT
>Thank you, Doug!
>
[quoted text clipped - 5 lines]
>points is really something MS should include. Any solution that requires
>try-catch feels like a 'hack' to me.

I agree. Maybe you could filter by testing the attributes?

Signature

Doug Harrison
Visual C++ MVP

Peteroid - 03 Nov 2007 23:48 GMT
> I agree. Maybe you could filter by testing the attributes?

Ah crap. I found the Directory class before the DirectoryInfo class (I
should have known better, I was already working eith DriveInfo and FileInfo
classes). I didn't realize I could get attributes since Directory class only
returns the names of the directories.

I did all of my runtime discovery of folders ala try-catch (e.g., that's how
I found out a directory was read-only). But I got 'distracted' with the
Directory class and never thought to look for DirectoryInfo class. Back to
the drawing board (System::Drawing class, for the record).

That was my first instinct. But GetDirectories( ) only returns an array of
the

>>Thank you, Doug!
>>
[quoted text clipped - 7 lines]
>
> I agree. Maybe you could filter by testing the attributes?

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.