Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

System.IO.Directory.GetFiles Empty

Tags:

c#

Can anyone shed light on why GetFile() is empty when I enumerate "C:\Windows\System32\Tasks"?

System.IO.Directory.GetFiles(@"C:\Windows\System32\Tasks");

I have checked this:

  • VS is running as Admin

  • No exception is thrown

  • There are files in root

  • I can copy files out (via explorer) to another folder and it works

like image 703
Shaun Vermaak Avatar asked Sep 02 '16 08:09

Shaun Vermaak


People also ask

What is directory GetFiles?

GetFiles(String, String, SearchOption) Returns the names of files (including their paths) that match the specified search pattern in the specified directory, using a value to determine whether to search subdirectories.

What is the use of the public function GetFiles as FileInfo()?

Public Function GetFiles As FileInfo()Returns a file list from the current directory. For complete list of properties and methods please visit Microsoft's documentation.

What does it mean to empty directory?

An empty directory contains no files nor subdirectories. With Unix or Windows systems, every directory contains an entry for “ . ” and almost every directory contains “ .. ” (except for a root directory); an empty directory contains no other entries.


2 Answers

The problem here is that you are running the program as x86, and it's being silently redirected to another folder that has no files in it. (It will be redirected to C:\Windows\SysWOW64\Tasks)

If you compile it as x64 or AnyCPU, you should see the files.

like image 71
Matthew Watson Avatar answered Oct 19 '22 17:10

Matthew Watson


Just an assumption. Do you use any try catch blocks? This folder can have permission settings which can give you access denied error and void try catch block doesn't show you any error.

like image 37
Dmitrij Kirikil Avatar answered Oct 19 '22 18:10

Dmitrij Kirikil