Using If File.exists to handle exceptions and not working as intended

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
<pre class="prettyprint Process p = new Process();
if (File.Exists(@"C:ProgramOneupdater.exe"))
{
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.FileName = Environment.ExpandEnvironmentVariables(@"C:ProgramOneupdater.exe");
p.Start();
}
else
{
Console.WriteLine("The File is either missing or is installed to a different location");
}
//string errorB = p.StandardError.ReadToEnd();//
p.WaitForExit();
//Total ICU//
if (File.Exists(@"C:ProgramTwoUpdater2.exe"))
{
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.FileName = Environment.ExpandEnvironmentVariables(@"C:ProgramTwoUpdater2.exe");
p.StartInfo.Arguments = "2";
p.Start();
}
else
{
Console.WriteLine("The File is either missing or is installed to a different location");
}[/code]
<br/>
The code above i want to look to see if the file exists at its current location and if not, the else statement runs and proceeds with the rest of the code.
Basically, it designed to run a multi-update process for a series of internal program, and if the program file is not there, it gives a message in console and moves onto the next line.
Problem is that its not doing that or running console.

<br/>

View the full article
 
Back
Top