Verify Existence of Directory

Dear Experts,

I have a  folder  in Table column  Path = "D:\DL\NewRpt\" that physically exists.

However, when I check using  Directory.Exists("D:\DL\NewRpt\")  always return negative.


Any help would be gladly appreciated.
JimiJ13I T ConsultantAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

JimiJ13I T ConsultantAuthor Commented:
It will return true if I use Directory.Exists(@"D:\DL\NewRpt\")  but how it can be formatted that way upon retrieving the value from table column?
0
käµfm³d 👽Commented:
Because you're forgetting that backslash means something special inside of C# strings. You need to escape the slashes in order to treat them as a part of the path and not special characters. You can do that in two ways:

Double-Up
Directory.Exists("D:\\DL\\NewRpt\\")

Open in new window


Use the @ Modifier
Directory.Exists(@"D:\DL\NewRpt\")

Open in new window

0
JimiJ13I T ConsultantAuthor Commented:
That's right but how it can be formatted using column value as variable?
0
PMI ACP® Project Management

Prepare for the PMI Agile Certified Practitioner (PMI-ACP)® exam, which formally recognizes your knowledge of agile principles and your skill with agile techniques.

käµfm³d 👽Commented:
I do not understand the question.
0
JimiJ13I T ConsultantAuthor Commented:
The Directory can be dynamically at the table Settings with the value as shown attached. That value shall be retrieved every time, as is, but it will not be recognized by C# unless formatted as:   "D:\\DL\\NewRpt\\" or @"D:\DL\NewRpt\".

 I hope that makes sense.
Directory.png
0
käµfm³d 👽Commented:
Since you are receiving that value from the user, there is no formatting required--C# will take care of it. The user can type it in the same way that is shown in your screenshot. If you're getting an error from what is shown in the screenshot, then the directory does not exist.
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
JimiJ13I T ConsultantAuthor Commented:
I wonder why I was not getting that same result earlier, now is working fine. Thanks anyway for leveling up my understanding.
0
JimiJ13I T ConsultantAuthor Commented:
Thanks.
0
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.