Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (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 by divil
Posted

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

  • *Experts*
Posted
Since you know how to enumerate the drives, just go through each one and use
If Directory.Exists(DriveLetter & "\Messages") Then
 ' The directory is on this drive
End If

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...