Link to home
Start Free TrialLog in
Avatar of JimiJ13
JimiJ13Flag for Philippines

asked on

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.
Avatar of JimiJ13
JimiJ13
Flag of Philippines image

ASKER

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?
Avatar of kaufmed
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

Avatar of JimiJ13

ASKER

That's right but how it can be formatted using column value as variable?
I do not understand the question.
Avatar of JimiJ13

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

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 JimiJ13

ASKER

I wonder why I was not getting that same result earlier, now is working fine. Thanks anyway for leveling up my understanding.
Avatar of JimiJ13

ASKER

Thanks.