How to modify a C# console application to use a constant for a directory path?

I am developing a C# console application.

How would you modify the following directory paths using a constant so that if the directory path were to change, I wouldn't have to make mulitple changes?

Currently I point to path u:\Harris\ which is where my files currently reside.

  class Class1
    {
        static void Main(string[] args)
        {

            string goodFilePath = @"f:\Harris\BK.BK.ARB4.ARB4.77.1.ard.ind";
            string emptyFilePath = @"f:\Harris\HRSBK.BK.B4.B4.77.1.ard";
            string tiffFilePath = @"f:\Harris\BK.BK.ARB4.ARB4.77.1.ard.out";
            string errorFilePath = @"f:\Harris\Check.err.txt";

            if (File.Exists(goodFilePath))
            {
                File.Delete(goodFilePath);
            }

            if (File.Exists(emptyFilePath))
            {
                File.Delete(emptyFilePath);
            }

            if (File.Exists(tiffFilePath))
            {
                File.Delete(tiffFilePath);
            }

            if (File.Exists(errorFilePath))
            {
                File.Delete(errorFilePath);
            }


            DirectoryInfo parentDirectory = new DirectoryInfo(@"f:\Harris");
zimmer9Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

käµfm³d 👽Commented:
const string TARGET_DIR = @"f:\Harris\";

string goodFilePath = Path.Combine(TARGET_DIR, "BK.BK.ARB4.ARB4.77.1.ard.ind");
string emptyFilePath = Path.Combine(TARGET_DIR, "HRSBK.BK.B4.B4.77.1.ard");
string tiffFilePath = Path.Combine(TARGET_DIR, "BK.BK.ARB4.ARB4.77.1.ard.out");
string errorFilePath = Path.Combine(TARGET_DIR, "Check.err.txt");

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.