Neutrino Posted June 23, 2003 Posted June 23, 2003 (edited) Hi Frenz, I created a Console Application in C:\ConsoleApp . I have a folder named "Messages" in my "D:\" . But when I try to use the DirectoryInfo Class to get the Root Directory it gave me erroneus results. Code: DirectoryInfo objDir = new DirectoryInfo("\\Messages); string rootErrorDir = objDir.Root.ToString(); string rootErrDir = objDir.FullName.ToString(); Console.Write(rootErrorDir); Console.Write(Environment.NewLine); Console.Write(rootErrDir); Console.Read(); When I executed the above code, it gave me the FullName as "C:\Messages" instead of "D:\Messages". Even the "Root" is given as "C:\". Similarly just for error elimination purposes, I deleted the above folders et stuff. Now I created the folder "Messages" in my "C:\" and the same project with the same code in my D:\ (same as the above example except interchanged). Its getting even weird now, it returns me the FullName as "D:\Messages" instead of "C:\Messages" and the Root as "D:\". Can neone give me a suitable explanation for the above behaviour? Amicalement, Neutrino Edited June 23, 2003 by divil Quote
*Gurus* Derek Stone Posted June 23, 2003 *Gurus* Posted June 23, 2003 It appears to be working as expected. A root drive is not specified in the constructer of the DirectoryInfo object, and therefore the root will default to the current working directory. Quote Posting Guidelines
Neutrino Posted June 24, 2003 Author Posted June 24, 2003 What should I do if I want to do a search in my other drives if I am currently in my C:\ drive? In this case I am not sure about the availablitt of the other drives and it could also be a mapped drive on a network? We can find the Logical Drives, but how do I search for a particular folder in another drive when I am currently no in that drive. Can you please help out? Amicalement, Neutrino Quote
*Experts* Volte Posted June 24, 2003 *Experts* Posted June 24, 2003 Since you know how to enumerate the drives, just go through each one and useIf Directory.Exists(DriveLetter & "\Messages") Then ' The directory is on this drive End If Quote
Neutrino Posted June 24, 2003 Author Posted June 24, 2003 Thanx man, It worked perfectly fine. Amicalement, Neutrino Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.