using Microsoft.Win32; using System.IO; using System.Windows; namespace VideoConcat { /// /// Video.xaml 的交互逻辑 /// public partial class Video : Window { public string text = ""; public Video() { InitializeComponent(); Check_Folder(); } private async void Button_Click(object sender, RoutedEventArgs e) { startButton.IsEnabled = false; await Task.Run(() => { for (int i = 0; i <= 100; i++) { System.Windows.Application.Current.Dispatcher.Invoke(() => { processVideoBar.Dispatcher.Invoke(() => { processVideoBar.Value = i; }); outputTxt.Dispatcher.Invoke(new Action(() => { WriteTxt("正在生成第" + i + "个视频"); })); }); System.Threading.Thread.Sleep(50); } startButton.Dispatcher.Invoke(() => { startButton.IsEnabled = true; }); });//ProcessVideo.RunTask(processVideoBar, startButton) } private void Check_Folder() { Boolean hasHead; Boolean hasTail; string currentPath = Directory.GetCurrentDirectory(); DirectoryInfo? parentPathInfo = Directory.GetParent(currentPath); if (parentPathInfo == null) { WriteTxt("获取相关视频文件目录失败!"); return; } WriteTxt(parentPathInfo.FullName); try { DirectoryInfo dirD = parentPathInfo as DirectoryInfo; FileSystemInfo[] folders = dirD.GetDirectories();//获取文件夹下所有文件和文件夹 //对单个FileSystemInfo进行判断,如果是文件夹则进行递归操作 foreach (FileSystemInfo folder in folders) { WriteTxt($"{folder.Name}"); if (folder.Name == "head") { hasHead = true; } if (folder.Name == "tail") { hasTail = true; } } //if (hasHead) //{ // WriteTxt("存在head文件夹"); //} } catch (Exception ex) { MessageBox.Show(ex.Message); return; } } private void WriteTxt(string str) { text += str + "\r\n"; outputTxt.Text = text; scrowText.ScrollToEnd(); } } }