我有这个我似乎无法克服的问题。我正在尝试列出所有目录和子目录。这是我到目前为止的代码:
String[] Folders;
String[] Files;
path = Server.MapPath("/");
DirectoryInfo dir = new DirectoryInfo(path);
Folders = Directory.GetDirectories(path);
try
{
FolderListing.Append("<ul id=\"FolderList\">");
for (int x = 0; x < Folders.Length; x++ )
{
DirectoryInfo folder = new DirectoryInfo(Folders[x]);
FolderListing.Append("<li>").Append(folder.Name).Append("</li>");
CheckSubdirectories(Folders[x]);
}
FolderListing.Append("</ul>");
FolderList.Text = FolderListing.ToString();
}
catch (Exception exc) //Module failed to load
{
Exceptions.ProcessModuleLoadException(this, exc);
}
}
private void CheckSubdirectories(string currentpath)
{
String[] subfolders = Directory.GetDirectories(currentpath);
if (subfolders.Length != 0)
{
FolderListing.Append("<ul id=\"SubFolderList\">");
}
for (int x = 0; x < subfolders.Length; x++ )
{
DirectoryInfo sfolder = new DirectoryInfo(subfolders[x]);
FolderListing.Append("<li>").Append(sfolder.Name).Append("</li>");
}
if (subfolders.Length != 0)
{
FolderListing.Append("</ul>");
}
path = currentpath.ToString();
}
我希望最终结果是:
<ul>
<li>admin</li>
<ul>
<li>Containers</li>
<li>ControlPanel</li>
<li>Menus</li>
<ul>
<li>etc etc</li>
</ul>
</ul>
</ul>
如果有人可以帮助我请