i'm writing setup code for setting file paths to exe's and some configs. I'm running a test just to make sure i'm doing this right, but getting a strange result.
I know for a fact that the file I'm searching for is at C:\ti\uniflash_3.4\uniflashCLI.bat
the following code correctly finds the file i want.
var uniflashEXE = Directory.GetFiles(@"C:\ti", "uniflashCLI.bat", SearchOption.AllDirectories);
This is where the installer of the program puts it by default, but I won't be surprised if it gets installed into ProgramFiles instead by my users (I won't be overseeing the installation)
To account for that I changed the code to
var uniflashEXE = Directory.GetFiles(@"C:\", "uniflashCLI.bat", SearchOption.AllDirectories);
but it doesn't work. I'm not getting any unauthorized user exceptions that should be thrown in the case of a UAC issue, and I've tried running Visual Studio (2015 community) as an Administrator to be sure.
This code is running in a form load (currently) and outputting the filepath to a messagebox the just displays the filepath. When running normally, this MessageBox pops up before the form loads and the form waits for me to press OK to load the form. When i change the directory to "C:" (or C:\ - it doesn't seem to matter) it just bypasses the entire process and just loads the form.
Whats going on here? It doesn't act like it's a permission issue and I know it's there, but when I ask it to search the entire directory it doesn't even try.
I get why searching the entire C directory would be a terrible idea, but i don't understand why it wouldn't do anything. More than likely I will try to identify likely installation spots and search through those directories and put a browse option for the edge cases that install in weird spots (though it scares me to do that, because these particular users are....well, they're not bright)
EDIT: adding entire code as requested
private void frmInitialSetup_Load(object sender, EventArgs e)
{
try
{
var uniflashEXE = Directory.GetFiles(@"C\:", "uniflashCLI.bat", SearchOption.AllDirectories);
MessageBox.Show(uniflashEXE[0].ToString());
}
catch (UnauthorizedAccessException UAex)
{
MessageBox.Show(UAex.ToString());
}
catch(DirectoryNotFoundException DNFex)
{
MessageBox.Show(DNFex.ToString());
}
}
EDIT2:
I placed a break point on both lines inside the try block.
When the code is set to search C:\ti and I stop it on the second line and hover over uniflashEXE it lists it as "uniflashEXE {string[1]}" and i can expand it to see that it contains the correct filepath. When it is set to search C:\ and do the same, it is listed as "uniflashEXE null".
I suppose passing a null value to a messagebox just makes it not show up and skips that whole section. It doesn't however, explain why it isn't searching through C:. Is it possible there's a maximum size that you can search through? The C:\ drive is 240 GB (ok, actually 223) while I only have 8 GB RAM.