Click here to Skip to main content
15,889,732 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
I'm trying to get all the subDirectories of a directory using the:
DirectoryInfo.GetDirectories("*",SearchOption.AllDirectories).

On all folders i have tested this is returns correct results
BUT

If u execute this on "C:\Windows\System32 you will find 2 problems:

1.(Solved) Is about a folder that u don't have permisions, don't remember the name but if you browse the path through the explorer, Windows asks to get permission and once got, It all works Fine.

2.Running it again you will see that it executes with no exceptions
BUT
Directories are missing !!!
No exception thrown..Nothing

After searching it for a while i found a directory that's missing.
"C:\Windows\System32\appmgmt" for example, I suppose it exists on all machines.

The strange thing is that if you execute the [DirectoryInfo.GetDirectories(..)] with the sourceDirectory = "C:\Windows\System32\appmgmt"

you will end up with a DirectoryNotFoundException and the elegant message:
"Could not find a part of the path 'C:\Windows\System32\appmgmt\'."

The directory is there...It just doesn't see it or like it or...:(

Quick Download Solution File to see for yourself : http://www.filesonic.com/file/1034796551/DSS_-_Copy.rar[^]
Posted
Updated 18-May-11 23:46pm
v3

I can't see any problem with GetDirectories. Then again, I'm an admin on my own machine and don't have UAC running.

From what I can tell, you cannot get all the folders without being an admin on the machine and running the code as an admin. If you have UAC enabled on your machine, your code is running as a normal user account until UAC kicks in and prompts you for elevation. Maybe you should add a manifest to the app and try it that way. Read this[^] to find out how.
 
Share this answer
 
Comments
Freeboss 19-May-11 5:23am    
I'm an admin too and don't have UAC running...
Freeboss 19-May-11 5:37am    
Windows Explorer on System32-Properties Returns me: 17.176 Files, 1.467 Folders
while code returns me 11.728 Files, 1289 Dirs...
Dave Kreskowiak 19-May-11 9:41am    
I see what you're getting at. There are folders that are secured by the system that you cannot get into. Some of them will let you get into them and you can see them in the folder/file count in Explorer, but will not let you see what's inside when using GetDirectories and GetFiles. You can see them in Explorer with a little yellow lock image on the folder icon. There is no way around this.
Freeboss 19-May-11 10:03am    
Well then what i can do..?
Go with unmanaged and foreign libraries, don't like it but seems the only solution..

PS..Sync toy from microsoft seems to return the correct results, no libraries access however.Would be shame to go Java at a C# enviroment.
Dave Kreskowiak 19-May-11 10:23am    
To do WHAT?? WHy would you want to get into folder you're not supposed to be screwing with in the first place?
I found the solution.

It's not some folders that are secured or anything..
If it was this even Windows Explorer wouldn't show em.

Anyway Visual Studio 2010 with or without Sp1 has by default "Platform Target" x86.

So if you run this on a x64 machine, the Framework does something like compatibility mode causing the faulty Results.
Even if you try adding a Folder Browser dialogue contol you will eventually see that again some Folders are missing.

So if you just set the "Platform Target" to "Any CPU", the problem is gone..Duh
 
Share this answer
 
Post is old but for future reference here is the solution i found:

http://alphafs.codeplex.com/[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900