Click here to Skip to main content
16,012,153 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi.
Being looking all over the System.IO namespace. Am I on the wrong path her? I just want to get a full qualified path (string) to any directory i choose by knowing just that existing directorys name.
Please, any suggestions?

Have a nice day.
Posted
Comments
OriginalGriff 19-Nov-10 7:34am    
Answer updated

1 solution

If what you are asking for is:
Supply a directory name ("MyExcelSpreadheets2010" for example)
Call a method which returns the fully qualified path to that directory.
string fileName = "MyExcelSpreadheets2010";
string path = GetFullPathFromJustTheDirectoryName(fileName);
expected path to contain "C:\WhereIKeepThings\Documents\Mine\ThisYear\MyExcelSpreadheets2010"

Then no. It doesn't exist. You will have to write it.
Think about it:
What if it isn't on C:, but on your DVD drive? Or your other HDD? Or a networked drive? USB drive, which happens to be in your pocket?

What if you have two directories with the same name? I do - lots. "bin" and "debug" are prime examples, but there are loads of others.

"Thats just the mattar. I cant se all the trees for the hole forest. What I mean is. Writing the code that gets the path without consideration to the mentiond problems. The problems where it is or is not, I can firure out. Lets just say it is on C:\. What I need just now is a push in the right direction. What Clases and methods, to use in what order can be a great help."

Ah! You should have said!

You need to set up a recursive method which looks at all the directories in a given path.
This will be a bit brief, because I'm pushed for time today (work just gets in the way, doesn't it?) You need to look at the Directory class:

bool Directory.Exists(path)
string[] Directory.GetDirectories(path)


Look them up on MSDN - there are probably examples.

You will probably need to have some kind of "found it - abort" flag for your recursive method, and I recommend testing on a small sub-branch of C:\ - it is probably worth setting up a small test directory with a known structure for testing.
 
Share this answer
 
v2
Comments
Sandeep Mewara 19-Nov-10 1:29am    
Comment from OP:
Thats just the mattar. I cant se all the trees for the hole forest. What I mean is. Writing the code that gets the path without consideration to the mentiond problems. The problems where it is or is not, I can firure out. Lets just say it is on C:\. What I need just now is a push in the right direction. What Clases and methods, to use in what order can be a great help.
Thanks for the considoration

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900