2个回答
展开全部
一楼的代码肯定会异常退出.
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace ConsoleApplication13
{
class Program
{
static void Main(string[] args)
{
EnumAllFiles("C:\\");
Console.ReadLine();
}
public static void EnumAllFiles(string path)
{
bool isError = false;
string[] subFiles = null;
string[] subDirs = null;
try
{
subFiles = Directory.GetFiles(path);
}
catch (Exception e)
{
isError = true;
}
if (!isError)
{
foreach (string file in subFiles)
{
Console.WriteLine(file);
}
}
isError = false;
try
{
subDirs = Directory.GetDirectories(path);
}
catch (Exception e)
{
isError = true;
}
if (!isError)
{
foreach (string dir in subDirs)
{
EnumAllFiles(dir);
}
}
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace ConsoleApplication13
{
class Program
{
static void Main(string[] args)
{
EnumAllFiles("C:\\");
Console.ReadLine();
}
public static void EnumAllFiles(string path)
{
bool isError = false;
string[] subFiles = null;
string[] subDirs = null;
try
{
subFiles = Directory.GetFiles(path);
}
catch (Exception e)
{
isError = true;
}
if (!isError)
{
foreach (string file in subFiles)
{
Console.WriteLine(file);
}
}
isError = false;
try
{
subDirs = Directory.GetDirectories(path);
}
catch (Exception e)
{
isError = true;
}
if (!isError)
{
foreach (string dir in subDirs)
{
EnumAllFiles(dir);
}
}
}
}
}
展开全部
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
string root = @"C:\";
DirectoryInfo info = new DirectoryInfo(root);
ViewDirectory(info);
Console.ReadKey();
}
static void ViewDirectory(DirectoryInfo info)
{
try
{
FileInfo[] files = info.GetFiles();
//show all files
if (files != null
&& files.Length > 0)
foreach (FileInfo file in files)
{
Console.WriteLine(file.FullName);
}
DirectoryInfo[] directoies = info.GetDirectories();
//show all sub directories
if (directoies != null
&& directoies.Length > 0)
{
foreach (DirectoryInfo d in directoies)
{
Console.WriteLine(d.FullName);
ViewDirectory(d);
}
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
return;
}
}
}
}
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
string root = @"C:\";
DirectoryInfo info = new DirectoryInfo(root);
ViewDirectory(info);
Console.ReadKey();
}
static void ViewDirectory(DirectoryInfo info)
{
try
{
FileInfo[] files = info.GetFiles();
//show all files
if (files != null
&& files.Length > 0)
foreach (FileInfo file in files)
{
Console.WriteLine(file.FullName);
}
DirectoryInfo[] directoies = info.GetDirectories();
//show all sub directories
if (directoies != null
&& directoies.Length > 0)
{
foreach (DirectoryInfo d in directoies)
{
Console.WriteLine(d.FullName);
ViewDirectory(d);
}
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
return;
}
}
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询