用C#监视多个文件夹,然后调用flvmdi对这个flv文件进行信息注入.

来源:互联网 发布:pola局部淡斑精华知乎 编辑:程序博客网 时间:2024/05/16 11:43

写一个应用程序,监视一个文件夹,如果文件里面有新的FLV文件,则调用flvmdi对这
个flv文件进行信息注入.

flvmdi文件我等会儿会放到你的共享文件里
关于flvmdi的用法可以查看:http://www.buraks.com/flvmdi/ 

 

 

private const string FILE_PATH = @"C:Documents and SettingsAdministratorMy DocumentsVisual Studio 2005ProjectsWatchFolderWatchFolderinReleaseConfig.txt";

        
private void btnStartWatching_Click(object sender, EventArgs e)
        
{
            
this.Text = "Watching ... ...";
            
string[] FileList = readFile();


            
this.FSWFileWatch.Path= FileList[1];
            
/*string[] cont = readFile();            

            for (int i = 1; i < cont.Length; i++)
            {
                if (cont.GetValue(i) != null)
                {
                    FileSystemWatcher FW = new FileSystemWatcher(cont.GetValue(i).ToString());
                    FW.Created += new FileSystemEventHandler(FSWFileWatch_Created);
                    FW.BeginInit();
                    FW.EnableRaisingEvents=true ;
                }
            } 
*/
                
        }
   

        
private void FSWFileWatch_Created(object sender, System.IO.FileSystemEventArgs e)
        
{       
           
string name = e.Name;
           
string path = e.FullPath;
            
            
try
           
{

               
if (System.IO.Path.GetExtension(name) == ".flv")
               
{
                   Process P;
                   P 
= Process.Start("flvmdi.exe",path);

                   
if (P.HasExited)
                   

                        
//进程已经退出
                   }


                   
//MessageBox.Show("File " + name + "Created! Directory:" + path);
               }

           }

           
catch (Exception ex)
           
{
               MessageBox.Show(
"Exception Message:"+ex.ToString());
           }

            
        }


        
private static string[] readFile()
        
{
            StreamReader sr 
= new StreamReader(FILE_PATH, System.Text.Encoding.UTF8);
            
string[] content =new string[5];
            
int i = 0;
            
try
            
{
                
while (sr.Peek() != -1)
                
{
                    i
++;
                    content[i] 
= sr.ReadLine();
                }

            }

            
catch (Exception fileex)
            
{
                MessageBox.Show(
"File Exception:"+fileex.ToString());
            }

            
return content;            
        }
原创粉丝点击