这个是一个 .bat文件
我想用 IO 把 每行 带 echo 的全删掉 只把 copy 和 pause 留住。
如何用IO 操作?
最主要的是 如何 改写文件 内容 这段IO echo 我要删掉sfdasfas12321
echo 我要删掉safdgsfdaecho 我要删掉adsfdsascopy Lujing 1  mubiaoPath 
copy Ling1 mubiaoPathecho begindsfdadsfadsXXXXSSSS
echo DFASFDSFDSDSS!!!!echo SDASFA!!!!!!!echo XXXXXXXXXXXXXXXXXXXXXXXXX
pause
最终我要的文件结果

copy Lujing 1  mubiaoPath 
copy Ling1 mubiaoPath
pause谢谢各位

解决方案 »

  1.   

    保存到其他文件中去。打开读文件的流
    打开写入文件的流
    while (读取一行)
    {
      if (echo开始)
         continue;
      
       写入这行
    }
      

  2.   

    1.bat是原bat文件,改为你实际的文件路径,2.bat是修改后的文件,改为你要保存的文件路径。        static void Main(string[] args)
            {
                StreamReader sr = new StreamReader("c:\\1.bat");
                StreamWriter sw = File.CreateText("c:\\2.bat");
                while (!sr.EndOfStream)
                {
                    string tmp = sr.ReadLine();
                    if (tmp.Length > 0 && !tmp.Trim().ToLower().StartsWith("echo"))
                    {
                        sw.WriteLine(tmp);
                    }
                }
                sr.Close();
                sw.Close();
            }
      

  3.   

    通过IO将内容读取后放到字符串中
    再利用Replace方法去掉echo
    string str=str.Replace("echo", "");
      

  4.   

    List<string> lst=new List<strin>(File.ReadAllLines(""))
    for(int i=0;i<lst.Count;i++)
    {
     lst[i]=lst[i].Replace("echo","");
    }
    File.WriteAllLines
      

  5.   

    StreamReader sr = new StreamReader(@"源文件");
               StreamWriter sw = new StreamWriter(@"文件", true,System.Text.Encoding.Default);
               while (sr.Peek() > -1)
               {
                   s=sr.ReadLine();
                   sw.Write(s.artsWith("echo")?s.Replace("",""):s);
                   sw.Flush();
               }
      

  6.   

    很感谢。
                StreamReader sr1 = File.OpenText(path1 + @"\AutoBuild.bat");
                string bat = string.Empty;
                while (!sr1.EndOfStream)
                {
                    string tempstr = sr1.ReadLine();
                    if (tempstr.Length > 0 && !tempstr.Trim().ToLower().StartsWith("echo"))
                    {
                        bat += tempstr+"\r\n";
                    }
                }
                string sps = bat.Replace("copy .", "copy " + path1);