I need to do a check to see if the file exists that they input, How can I do this, I tried using try & catch and it has no effect
if (startarg.Contains("-del") == true)
{
//Searches "Uninstallers" folder for uninstaller containing the name that they type after "-del" and runs it
string uninstalldirectory = Path.Combine(Directory.GetCurrentDirectory(), "Uninstallers");
DirectoryInfo UninstallDir = new DirectoryInfo(uninstalldirectory);
string installname = startarg[2].ToString();
//Removes file extesion "-del "
installname.Remove(0, 5);
string FullFilePath = Path.Combine(uninstalldirectory, installname);
try
{
//Makes the uninstaller invisible to the user and sets other settings
Process Uninstaller = new Process();
Uninstaller.StartInfo.FileName = FullFilePath;
Uninstaller.StartInfo.UseShellExecute = false;
Uninstaller.StartInfo.CreateNoWindow = true;
Uninstaller.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
Uninstaller.Start();
}
//Only is run if the package isn't installed
catch (System.Exception)
{
Console.WriteLine("The specified package is not installed, you most likely mispelled it or didnt put quotes around it, try again");
}
}
Most of that code is getting the current directory and adding "Uninstallers" to it.
Edit: The debug result is a ArgumentOutOfRangeException
I tried using the File.Exists if statement and else and it still crashes
Edit #2:
Just a bit on what I'm to do with this program: I'm trying to write a cross-platform (with mono, haven't ported it yet because I don't like MonoDevelop) package manager, and this is the function of it that deletes the packages. It gets the list of installed applications by getting the uninstall scripts in the Uninstallers folder of the application. I want it to be directory independent so I have it get the current directory
My code works fine if the file exists, but when it doesn't it crashes thats my problem