Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 455989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T22:25:35+00:00 2026-05-12T22:25:35+00:00

I need to do a check to see if the file exists that they

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T22:25:35+00:00Added an answer on May 12, 2026 at 10:25 pm

    The try-catch has no effect because the exception is being thrown by code that is outside of the try block. As the other answers point point out, there are several improvements you can make to your code so that your exception handling is invoked for truly exceptional conditions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to check that the received file exists in Photo Library Let me
When our server comes up we need to check a file to see how
I need to check specific positions in an NSArray to see if they have
I want to quickly check to see if a file exists in my iPhone
I need help with adding the feature to check whether a file exists when
I need to check to see if a directory is empty. The problem is,
I need to check a directory to see if there are any files whose
I need a jquery script section that checks to see if the first digit
I need to check if my address has any words that matches word in
I need to daily run a script that will download a file from a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.