C#的文件操作。。。。。。。。。。。。。。。。

此用户昵称已被屏蔽 2011-10-26 11:00:39
程序运行结果不正确 下面是简化的:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace File1
{
class Program
{
public static void Main(string[] args)
{
if (args.Length == 0 || args[0].Length != 1)
{
ShowUage();
return;
}


switch (args[0] )
{
case"d":
DeleteFile(args );

break ;

default :
ShowUage();
break ;
}
Console.ReadKey();

}
public static void ShowUage()
{


Console .WriteLine ("使用方法:\n");
Console .WriteLine ("File Option<功能选项><源文件>[目标文件]");
Console .WriteLine ("<功能选项>");
Console .WriteLine ("\td-删除文件");
Console.ReadLine();


}

public static void DeleteFile(string [] files)
{

string sourceFile;
GetFileName (files ,out sourceFile );
if (!File .Exists (sourceFile ))
{
Console .WriteLine ("文件操作失败:源文件不存在。");
return ;
}
try
{
File .Delete (sourceFile );
}
catch (Exception ex)
{
Console .WriteLine ("文件操作失败:"+ex .Message );
}
Console.ReadKey();
}
public static string InputFileName(string prompt)
{
string s = "";
do
{
Console.Write(prompt);
s = Console.ReadLine().Trim();
} while (s.Length == 0);
return s;

}
public static void GetFileName(string[] files, out string sourceFile)
{
if (files.Length >= 2)
{
sourceFile = files[1];
}
else
{
sourceFile = InputFileName("输入文件名==>");
}
Console.ReadKey();
}


}
}
...全文
120 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
lexfu 2011-12-22
  • 打赏
  • 举报
回复
哪不对?

1,979

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 其他语言讨论
社区管理员
  • 其他语言社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧