本文介绍了找不到FileSystemEntry的名称空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我找不到FileSystemEntry
的名称空间.谁能帮我一个忙?
I can''t find namespace for FileSystemEntry
. Who can do me a favor?
using System;
using System.IO;
using System.Security;
namespace DosAPI1
{
class MyExplorer
{
public static void Main(string[] args)
{
MyExplorer oExplorer=new MyExplorer();
string Command;
string[] CommandLineArgs;
int ArgumentLength;
bool CanExit=false;
Console.WriteLine("Welcome to the MyExplorer Dos Utility");
do
{
Console.Write("MyExplorer>");
Command=Console.ReadLine ();
Command=ToSingleSpace(Command.Trim().ToLower());
CommandLineArgs=oExplorer.ParseCommand(Command.ToLower(),out ArgumentLength);
switch(CommandLineArgs[0])
{
case"cpy":
if(ArgumentLength!=2)
{
ShowError("Usage cpy<source><dest>");
}
else
{
oExplorer.Copy(CommandLineArgs[1],CommandLineArgs[2]);
}
break;
case"rem":
if(ArgumentLength!=1)
{
ShowError("Usage rem<filename>");
}
else
{
oExplorer.Remove(CommandLineArgs[1]);
}
break;
case"dir":
case"ls":
switch(ArgumentLength)
{
case 0:
oExplorer.ListFiles(".");
break;
case 1:
oExplorer.ListFiles(CommandLineArgs[1]);
break;
default:
ShowError("Usage dir[<path>]");
break;
}
break;
case "help":
case "h":
oExplorer.ShowHelp();
break;
case "quit":
case "exit":
case "bye":
CanExit = true;
break;
default:
ShowError("Invalid Command");
break;
}
}while(!CanExit);
}
public static void ShowError(string StrError)
{
Console.WriteLine(StrError);
}
public static string ToSingleSpace(string StrToReplace)
{
int Position;
Position=StrToReplace.IndexOf(" ");
if(Position==-1)
return StrToReplace;
else
return ToSingleSpace(StrToReplace.Substring(0,Position)+StrToReplace.Substring(Position+1));
}
public string[] ParseCommand(string Command,out int ArgumentLength)
{
string[] CommandLineArgs=Command.Split(new char[]{' '});
ArgumentLength=CommandLineArgs.Length-1;
return CommandLineArgs;
}
/* Function to the Usage of MyExplorer*/
public void ShowHelp()
{
Console.WriteLine("MyExplorer Help Contents");
Console.WriteLine("-------------------------");
Console.WriteLine("cpy<source><dest>-Copies the content of source to dest");
Console.WriteLine("rem<filename> -Filename to be deleted");
Console.WriteLine("dir/ls[<path>] -Directory Listing");
Console.WriteLine("h/help -Help for using MyExplorer");
Console.WriteLine("quit/exit/bye -Exit MyExplorer");
}
/* Method to perform File Copy operation*/
public void Copy(string SourceFile,string DestinationFile)
{
try
{
File.Copy(SourceFile,DestinationFile,true);
Console.WriteLine("File Copied Successfully");
}
catch(FileNotFoundException)
{
Console.WriteLine("Source File does not Exists");
}
catch(ArgumentException)
{
Console.WriteLine("Invalid Argument for cpy");
}
catch(SecurityException)
{
Console.WriteLine("Write Access is Denied");
}
catch(Exception)
{
Console.WriteLine("UnKnown Exception");
}
}
/* Function to Delete the Specified File*/
public void Remove(string FileToRemove)
{
try
{
File.Delete(FileToRemove);
Console.WriteLine("File Removed Successfully");
}
catch(DirectoryNotFoundException)
{
Console.WriteLine("File does not exists");
}
catch(SecurityException)
{
Console.WriteLine("Delete Permission Denied");
}
catch(AccessException)
{
Console.WriteLine("Directory name is specified where file is required");
}
catch(Exception)
{
Console.WriteLine("UnKnown Exception");
}
}
/* Directory Listing*/
public void ListFiles(string StrDirectoryToList)
{
Directory oDir;
FileSystemEntry[] oFiles;
try
{
oDir=new Directory(StrDirectoryToList);
oFiles=oDir.GetFileSystemEntries();
bool IsFileFound = true;
foreach(FileSystemEntry f in oFiles)
{
if(IsFileFound)
{
Console.WriteLine("{0,-32}{1,8}{2}","Name","Size","Directory/File");
Console.WriteLine(new string('=',80));
IsFileFound=false;
}
if(f.IsFile)
{
Console.WriteLine("{0,-32}{1,8}{2}",f.Name,((File)f).Length,"F");
}
else
{
Console.WriteLine("{0,-32}{1,8}{2}",f.Name,"0","F");
}
}
}
catch(DirectoryNotFoundException)
{
Console.WriteLine("Directory Not Found");
}
catch(Exception)
{
}
}
}
}
推荐答案
oFiles = oDir.GetFileSystemEntries();
因此,在您的代码中而不是使用
So in your code instead of using
FileSystemEntry[] oFiles;
您应该使用
You should be using
string[] oFiles;
这篇关于找不到FileSystemEntry的名称空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!