using System;
using System.IO;
using System.Collections;
namespace Cmd
{
/// <summary>
/// Dispose 的摘要说明。
/// </summary>
public class Dispose
{
string cmd;
//string para;
object o;
public Dispose(string cmd,object obj)
{
//
// TODO: 在此处添加构造函数逻辑
//
this.cmd=cmd;
this.o=obj;
Run();
}
void Run()
{
switch (cmd)
{
case "cd":
cdcmd();
break;
case "dir":
dircmd();
break;
case "del":
delcmd();
break;
}
}
void cdcmd()
{
Input.Currentpath=((DirectoryInfo)o).FullName;
}
void dircmd()
{
ArrayList list=new ArrayList();
FileInfo[] fi=((DirectoryInfo)o).GetFiles();
foreach(FileInfo f in fi)
{
//Console.WriteLine(f.Name);
list.Add(f);
}
DirectoryInfo [] diarr=((DirectoryInfo)o).GetDirectories();
foreach(DirectoryInfo d in diarr)
{
//Console.WriteLine(d.Name+"\t\t<dir>");
list.Add(d);
}
new Output(list);
}
void delcmd()
{
try
{
((FileInfo)o).Delete();
Console.WriteLine("文件已经删除..");
}
catch(System.InvalidCastException)
{
Console.WriteLine("正在删除目录");
((DirectoryInfo)o).Delete(true);
Console.WriteLine("目录删除完毕");
}
}
}
}