using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Collections;namespace _oneline
{
    class Program
    {
        static void Main(string[] args)
        {
            string path = @"D:\\MS_HD_08_H576i25_to_H264_960x1080p25_4.sh";            string logstring = @"";            FileStream fs = new FileStream(path, FileMode.Open, FileAccess.ReadWrite, FileShare.None);
            StreamReader sr = new StreamReader(fs);            StreamWriter sr_ = new StreamWriter(fs);
            string[] _line = sr.ReadToEnd().Split('\r');            sr.Close();            for (int i = 0; i < _line.Length; i++)
            {                int _i = -1;
                int _h = -1;
                int _w = -1;                if (_line[i].ToString().IndexOf(@"-u32PID") > 0
                    && _line[i].ToString().IndexOf(@"-u32BitRate") > 0
                    && _line[i].ToString().IndexOf(@"-instance") > 0)
                {                    string[] temp = _line[i].ToString().Split(' ');                    for (int j = 0; j < temp.Length; j++)
                    {
                        if (temp[j].ToString() == @"-instance")
                        {                            _i = int.Parse(temp[j + 1].ToString());                        }                        if (temp[j].ToString() == @"-u32BitRate")
                        {                            _w = int.Parse(temp[j + 1].ToString());                        }                        if (_i == 9 || _i == 13 || _i == 8 || _i == 12 || _i == 10 || _i == 14)
                        {                            if (_w == 4000000)
                            {                                _line[i] = _line[i].Replace(@"-u32BitRate " + _w.ToString(), @"u32BitRate 400000");                            }
                        }
                    }
                }                logstring = logstring + _line[i].ToString();            }            StreamWriter logfile = new StreamWriter(path);
            logfile.WriteLine(logstring);
            logfile.Close();
            Console.ReadLine();
        }    }
}
C#

解决方案 »

  1.   

    var pathes=Dictionary.getFiles("文件夹路径");
    然后遍历所有文件
      

  2.   

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.IO;
    using System.Collections;namespace _oneline
    {
        class Program
        {
            static void Main(string[] args)
            {
                
                string folderpath = @"D:\M17\";            DirectoryInfo TheFolder = new DirectoryInfo(folderpath);
                //  aaa = conn_nxd.BeginTransaction();
                foreach (FileInfo NextFile in TheFolder.GetFiles())
                {
                    if (NextFile.Extension.ToUpper() != @".SH")
                    {                    continue;
                    }
                    string path = folderpath + NextFile.Name;
                    string logstring = @"";
                    int i = 0;                FileStream fs = new FileStream(path, FileMode.Open, FileAccess.ReadWrite, FileShare.None);
                    StreamReader sr = new StreamReader(fs);                StreamWriter sr_ = new StreamWriter(fs);
                    string[] _line = sr.ReadToEnd().Split('\r');                sr.Close();                if (_line[i].Contains("./xcode.configGenericVideoEnc.pl"))
                    {
                       for (i = 0; i < _line.Length; i++)
                       {                       int _i = -1;
                           int _h = -1;
                           int _w = -1;                       if (_line[i].ToString().IndexOf(@"-u32PID") > 0
                               && _line[i].ToString().IndexOf(@"-u32BitRate") > 0
                               && _line[i].ToString().IndexOf(@"-instance") > 0)
                           {                           string[] temp = _line[i].ToString().Split(' ');                           for (int j = 0; j < temp.Length; j++)
                               {
                                   if (temp[j].ToString() == @"-instance")
                                   {                                   _i = int.Parse(temp[j + 1].ToString());                               }                               if (temp[j].ToString() == @"-u32BitRate")
                                   {                                   _w = int.Parse(temp[j + 1].ToString());                               }                               if (_i == 9 || _i == 13 || _i == 8 || _i == 12 || _i == 10 || _i == 14)
                                   {                                   if (_w == 4000000)
                                       {                                       _line[i] = _line[i].Replace(@"-u32BitRate " + _w.ToString(), @"u32BitRate 400000");                                   }
                                   }
                               }                        }
                        }                    logstring = logstring + _line[i].ToString();                }                StreamWriter logfile = new StreamWriter(folderpath + NextFile.Name);
                    logfile.WriteLine(logstring);
                    logfile.Close();
                    Console.ReadLine();
                }        }    }
    }我这样改的  可是不行报错呢