Getting directory

R

Rinaldo

Hi,

I have a problem to get the directory.

I've tryed:

public void WriteWeb(DirectoryInfo directory)

{

DirectoryInfo[] subDirectories = directory.GetDirectories();

string Map = currentMap; // Global string to local string

string Web = currentWeb; // Global string to local string

if (subDirectories != null)

{

foreach (DirectoryInfo subDir in subDirectories)

{

Console.WriteLine(subDir.Name);

string Dir = subDir.Name;


Map += "\\" + subDir.Name;

Web += subDir.Name + "/";

// MessageBox.Show("Dir " + Web + "\n" + Map);

WriteWeb(subDir);

}

}

}

The problem is that if I have C:\pad\backup and there are 2 dirs in it (One
and Two) the complete dir will become C:\pad\backup\One\Two\ and not 2
seperate dirs in both Map and Web.

What I doing wrong,
 
M

Muhammed Soyer

Rinaldo said:
Hi,

I have a problem to get the directory.

I've tryed:

public void WriteWeb(DirectoryInfo directory)

{

DirectoryInfo[] subDirectories = directory.GetDirectories();

string Map = currentMap; // Global string to local string

string Web = currentWeb; // Global string to local string

if (subDirectories != null)

{

foreach (DirectoryInfo subDir in subDirectories)

{

Console.WriteLine(subDir.Name);

string Dir = subDir.Name;


Map += "\\" + subDir.Name;

Web += subDir.Name + "/";

// MessageBox.Show("Dir " + Web + "\n" + Map);

WriteWeb(subDir);

}

}

}

The problem is that if I have C:\pad\backup and there are 2 dirs in it
(One and Two) the complete dir will become C:\pad\backup\One\Two\ and
not 2 seperate dirs in both Map and Web.

What I doing wrong,
Looks like you want something as below

internal class Program
{
private string currentMap=@"c:\";
private string currentWeb=@"web/";

private static void Main(string[] args)
{
Program prg = new Program();
prg.WriteWeb(new DirectoryInfo(@"c:\aa\"), prg.currentMap,
prg.currentWeb);
Console.ReadLine();
}

public void WriteWeb(DirectoryInfo directory, string map,
string web)
{

DirectoryInfo[] subDirectories = directory.GetDirectories();



if (subDirectories != null)
{

foreach (DirectoryInfo subDir in subDirectories)
{
string tempMap = map;
string tempWeb = web;
Console.WriteLine(subDir.Name);

string Dir = subDir.Name;


tempMap += "\\" + subDir.Name;

tempWeb += subDir.Name + "/";

// MessageBox.Show("Dir " + Web + "\n" + Map);
Console.WriteLine("Dir " + tempWeb + "\n" + tempMap);
WriteWeb(subDir,tempMap,tempWeb);

}

}

}


}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top