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?
 
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
 
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
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
JimiJ13I T ConsultantAuthor Commented:
That's right but how it can be formatted using column value as variable?
0
 
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
 
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
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.

All Courses

From novice to tech pro — start learning today.