I need to create a full list of the files and sub-directories in a directory.
DirectoryInfo.GetFiles()
does NOT find all files; hidden files, at a minimum, seem to be missing.
(There may also be a problem with permissions, as I can't look inside some directories using Windows Explorer, even though I am running as Administrator. For instance, "C:\System Volume Information" can not be entered.)
I am using C#, Windows XP Pro
DirectoryInfo.GetFiles()
returns all files (excluding those that you don't have permission to see).
At the very least it definitely does include hidden files, as shown by this person who is asking almost exactly the reverse of this question.
Do you have a specific example of a file that appears elsewhere but not in this list?
Weighing in at this late date, GetFiles DOES NOT always return all files, and I haven't figured out why either. Here is one way to reproduce (at least on 64-bit Windows 7 Home, running as Administrator and using C# with Visual Studio 2010).
Install the FTDI Drivers EXECUTABLE installer from here (http://www.ftdichip.com/Drivers/D2XX.htm)
This will install the following files in \Windows\System32:
-ftbusui.dll
-ftcserco.dll
-ftd2xx.dll
-FTLang.dll
-ftserui2.dll
The following code:
String[] files = Directory.GetFiles(Environment.SystemDirectory, "f*.*", SearchOption.TopDirectoryOnly);
returns ftd2xx.dll, but not the other four files.
Changing the searchPattern to *.*, or simply using:
GetFiles(Environment.SystemDirectory)
returns ftd2xx.dll, but not the other four files.
None of the files are hidden and all five have the same Owner and Permissions. All five files show up in Windows Explorer and in a Command Prompt window.
In fact, the following returns false:
File.Exists(@"c:\Windows\System32\ftbusui.dll")
and the four files don't show up in a OpenFileDialog dialog. Running the executable as Admin makes no difference and turning off UAC doesn't help.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With