using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace MakeSql
{
class Program
{
static void Main(string[] args)
{
bool boolFlag=true ;
while (boolFlag)
{
Console.WriteLine("请输入你的sql文件路径:(Please input ur SQL or TXT filepath:)");
string strPath= Console.ReadLine();
if ("EXIT" == strPath.ToUpper())
{
boolFlag = false;
continue;
}
if (!File.Exists(strPath))
{
Console.WriteLine("该文件路径错误,请重新输入.(This filepath is error,please repeat input.)");
continue;
}
string strExpand = strPath.Substring(strPath.LastIndexOf("."));
if (!(".sql" == strExpand ) && !(".txt" == strExpand))
{
Console.WriteLine("该文件类型不支持,请重新输入.(This fileType is error,please repeat input.)");
continue;
}
using (FileStream fs = File.Open(strPath, FileMode.Open))
{
using (StreamReader sr = new StreamReader(fs))
{
try
{
FileStream newfs = new FileStream("D:/TempSQL.txt", FileMode.Append ,FileAccess.Write);
StreamWriter sw = new StreamWriter(newfs);
string date = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:ms");
sw.WriteLine();
sw.WriteLine("#####################################" + date + " BEGIN########################################");
while (sr.Peek() >= 0)
{
string strTemp = sr.ReadLine();
if (strTemp.StartsWith("-"))
{
sw.WriteLine("'" + strTemp);
}
else if (!string.IsNullOrEmpty(strTemp))
{
sw.WriteLine("sql.AppendLine(/"" + strTemp + "/")");
}
}
sw.WriteLine("#####################################" + date + " END############################################");
sw.WriteLine();
sw.Flush();
sw.Close();
newfs.Close();
Console.WriteLine(date + " 处理成功:(Successfully done.)");
Console.WriteLine("生成文件路径 D:/TempSQL.txt");
}
catch(Exception ex)
{
Console.WriteLine("处理失败:(Process failed:)");
Console.WriteLine(ex.Message );
}
}
}
}
}
}
}
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/raineo/archive/2009/06/25/4298411.aspx