c# 调用外部程序对文件夹内文件进行处理
DirectoryInfo TheFolder = new DirectoryInfo(path_video); //只获取一层,子文件夹没处理
foreach (FileInfo item in TheFolder.GetFiles("*.*"))
{
string name = item.Name;//处理目录下某一文件名
string fullname = item.FullName;//处理目录下带路径文件名
System.Diagnostics.Process Process1 = new System.Diagnostics.Process();
Process1.StartInfo.FileName = ffmpeg_address.Text;//调用外部程序名
Process1.StartInfo.Arguments= @"-i "+fullname+" -ss 2 -offset_x 10 -offset_y 20 -f image2 \""+path_img+"\\"+Path.GetFileNameWithoutExtension(name)+".jpg\" ";//调用程序参数
try
{
if (Process1.Start()) //开始进程
{
Process1.StandardOutput.ReadToEnd(); //读取输出流释放缓冲, 不加这一句,进程会一直无限等待
//MessageBox.Show(Process1.StandardOutput.ReadToEnd());
Process1.WaitForExit();
//MessageBox.Show("Process finished.");
}
}
catch (Exception ex)
{
Debug.Print("Exception !!!"+ex);//万一出错
}
}//end foreach
处理文件夹用下面的
DirectoryInfo TheFolder = new DirectoryInfo(path); //只获取一层,子文件夹没处理
foreach (DirectoryInfo item in TheFolder.GetDirectories()) {
string name = item.Name;//lv6下某一文件夹名
}
上一篇: c# 选择文件或文件夹
下一篇: 这一两天学习了一下视频编辑