.NET Framework Bookmark and Share   
 index > .NET Base Class Library > simple Directory.GetDirectories question
 

simple Directory.GetDirectories question

Hi Everyone,
I have a quick question about some usage. I need to return the base path of this class, in C#, meaning, when I call:
Code Snippet
string[] dirs = Directory.GetDirectories(Server.MapPath("../users/"));
foreach(string dir in dirs) {
Response.Write("\n" + dir);

I don't want C:\asdf1\asdf2\asdf3. I just want asdf3

In VB, I would call:

CodeSnippet

Dim fs
fs=Server.CreateObject("Scripting.FileSystemObject")
'-- Get directory listing into an array
FolderArray = Directory.GetDirectories(Server.MapPath("../users/"))

'-- Iterate the array items and display directories
For Each Item in FolderArray
response.Write("<a href=""" & fs.GetBaseName(Item) & """>" & fs.GetBaseName(Item) & "</a> </br>")
Next

and it would give me the base name and then link me to the full server path. I'm using this to driver further down in directories, so if it is at all possible to keep what I'm doing in c# intact, that would be greatly appreciated. Thank you

Pash91

Hi,

How about this:

Code Snippet

new DirectoryInfo(dir).Name

Joe
Joe Mayo

Hi,

How about this:

Code Snippet

new DirectoryInfo(dir).Name

Joe
Joe Mayo
You can use Path class for manipulating strings that are file or folder path.
Giorgi Dalakishvili

Use DirectoryInfo.GetDirectories() and the Name of the returned DirectoryInfos.

JohnWein
This was just what I needed!
Thank you so much
Pash91
I have an article about recursively finding files. Maybe it could give you some ideas? It is fairly popular

Recursively find files

Sam
smallen

You can use google to search for other answers

Custom Search

More Threads

• CompilerOptions.
• how to read .dat file
• wmi event consumption
• Registry
• System.Messaging - Occasional Error/Error Under Stress
• determine therad creator
• Generic control to print bar code labels
• Exception while using Process class
• Dotfuscate Delay Sign TroublShooting
• Dot Net 4.0 and Visual Studio 2010/11