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
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.
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.
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.
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.
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.
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