Writing some code in C#, I was wondering if there was a way to get the correct path of a directoryinfo object?
Currently I have, for example, a directory such as:
DirectoryInfo dirInfo = new DirectoryInfo(pathToDirectory);
The issue is that if I want to get the path of that specific dirInfo
object, it always returns the debug path (bin folder). If the original dirInfo object is referencing a directory in the D:\testDirectory
path, then I want a way to get that path again somewhere else in the code instead of getting \bin\debug\testDirectory
Is there any way to do this?
Currently I am trying to get the path of dirInfo using Path
:
Console.WriteLine("Path: " + Path.GetFullPath(dirInfo.ToString()));
dirInfo
? – TalmudistDirectoryInfo
"? And for sample code try to use constant values where possible (i.e. what is value ofpathToDirectory
when your code does not work) – CoauthorPath.GetFullPath(new DirectoryInfo(@"D:\testDirectory ").ToString())
returns "D:\testDirectory" as expected. Please double check your sample. – CoauthorDirectory.CreateDirectory("some\\relative\\pathtest")
it returns aDirectoryInfo
instance, but if you call.ToString()
on it then it will only return the same as the Name property, in this case:"pathtest"
- which is really weird, you would expect CreateDirectory to pass on the original string - but it doesn't! – Viscountess