请c sharp达人看看这段程序为什么会报错阿!在线等

darkzhan 2003-07-25 03:21:07
private string ReadFromFile(string filename)
{
string strDir2List ="d:/soft/";
Directory thisOne = null;
try
{
thisOne =new Directory(strDir2List); //错误一出现的地方
Directory[] subDirectories =thisOne.GetDirectories();//错误二出现的地方
return subDirectories[0].ToString();
}
catch (Exception e)
{
return "error";
}

}

错误一: 重载“Directory”方法未获取“1”参数

错误二:重载“GetDirectories”方法未获取“0”参数

...全文
33 4 打赏 收藏 举报
写回复
4 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
jinye 2003-07-25
  • 打赏
  • 举报
回复
Directory 换成 DirectoryInfo
kittyliy52 2003-07-25
  • 打赏
  • 举报
回复
试过了,你把Directory类换成DirectoryInfo类就可以了,呵呵
brightheroes 2003-07-25
  • 打赏
  • 举报
回复
你的string strDir2List ="d:/soft/"定义的有问题。
修改为strDir2List = @"d:\soft\";
雪狼1234567 2003-07-25
  • 打赏
  • 举报
回复
参看如下代码:
// For File.Exists, Directory.Exists
using System;
using System.IO;
using System.Collections;


// Takes an array of file names or directory names on the command line.
// Determines what kind of name it is and processes it appropriately
public class RecursiveFileProcessor {
public static void Main(string[] args) {
foreach(string path in args) {
if(File.Exists(path)) {
// This path is a file
ProcessFile(path);
}
else if(Directory.Exists(path)) {
// This path is a directory
ProcessDirectory(path);
}
else {
Console.WriteLine("{0} is not a valid file or directory.", path);
}
}
}


// Process all files in the directory passed in, and recurse on any directories
// that are found to process the files they contain
public static void ProcessDirectory(string targetDirectory) {
// Process the list of files found in the directory
string [] fileEntries = Directory.GetFiles(targetDirectory);
foreach(string fileName in fileEntries)
ProcessFile(fileName);

// Recurse into subdirectories of this directory
string [] subdirectoryEntries = Directory.GetDirectories(targetDirectory);
foreach(string subdirectory in subdirectoryEntries)
ProcessDirectory(subdirectory);
}

// Real logic for processing found files would go here.
public static void ProcessFile(string path) {
Console.WriteLine("Processed file '{0}'.", path);
}
}
发帖
C#

10.8w+

社区成员

.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
帖子事件
创建了帖子
2003-07-25 03:21
社区公告

让您成为最强悍的C#开发者