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

Posted on 2013-09-19
Medium Priority
Last Modified: 2013-09-19
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))

            if (File.Exists(emptyFilePath))

            if (File.Exists(tiffFilePath))

            if (File.Exists(errorFilePath))

            DirectoryInfo parentDirectory = new DirectoryInfo(@"f:\Harris");
Question by:zimmer9
1 Comment
LVL 75

Accepted Solution

käµfm³d   👽 earned 2000 total points
ID: 39506688
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


Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this video I will demonstrate how to set up Nine, which I now consider the best alternative email app to Touchdown.
Through the video, you can check the migration process of Outlook PST file to PDF. Kernel for Outlook to PDF tool can convert Outlook emails with all attributes like Subject, To, From, Cc, Bcc and other folders such as Inbox, Outbox, Sent Items, Jun…
Suggested Courses

600 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question