Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find all files, including hidden and system files

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

like image 958
Mark T Avatar asked Dec 06 '22 20:12

Mark T


2 Answers

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?

like image 151
Justin Avatar answered Dec 14 '22 23:12

Justin


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.

like image 29
Derek Johnson Avatar answered Dec 15 '22 01:12

Derek Johnson