Mark T
Mark T

Reputation: 3494

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

Upvotes: 4

Views: 7817

Answers (5)

Derek Johnson
Derek Johnson

Reputation: 1056

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.

Upvotes: 3

Adriano Carneiro
Adriano Carneiro

Reputation: 58635

As noted by the others, DirectoryInfo.GetFiles() gets all files. Thus, it looks like you might be hitting a permission issue.

Upvotes: 1

sll
sll

Reputation: 62544

It should. Try to search in an other directory, create manually hidden file and see whether it will be in search resultset.

Upvotes: 2

Justin
Justin

Reputation: 86779

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?

Upvotes: 7

Kirill Polishchuk
Kirill Polishchuk

Reputation: 56202

DirectoryInfo.GetFiles() returns all files including hidden files.

Upvotes: 2

Related Questions