Link to home
Start Free TrialLog in
Avatar of zimmer9
zimmer9Flag for United States of America

asked on

I am writing a C# console application and exit the app if a "txt" file is not present. However, the exe ALWAYS exits the app whether or not a "txt" file exists.

I am writing a C# console application using VS2015 and .Net Framework 4.6

I want to exit the application if the input "txt" file is not present in the directory \\NY\data\

Whether or not a txt file is present in the directory, the application takes the exit path.

What am I doing wrong in the following code?

public static class MyGlobals
    {
            public static string BASE_DIR = @"\\NY\data\";


 string inputTxtFilePath = MyGlobals.BASE_DIR + "*" + ".txt";


            if (File.Exists(inputTxtFilePath))
            {                
            }
            else
            {
                StreamWriter sw2 = new StreamWriter(errorFilePath);
                sw2.WriteLine("Input txt File not found");
                if (sw2 != null) sw2.Close();
                Environment.Exit(0);
            }
ASKER CERTIFIED SOLUTION
Avatar of Dr. Klahn
Dr. Klahn

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of zimmer9

ASKER

This seems to work as well:

bool exist = Directory.EnumerateFiles(MyGlobals.BASE_DIR, "*.txt").Any();