下面是一个C#应用程序的例子,可以做你正在问的东西。通过右键单击视频文件,选择Open With,然后选择C#应用程序的可执行文件(可以选中“始终使用选定程序打开此类文件”框以使更改为永久性)来启动它。
static void Main(string[] args)
{
if (args.Length < 1)
return;
string vlc = @"C:\Program Files\VideoLAN\VLC\vlc.exe";
string videoFile = args[0];
string pathAffected = @"C:\Users\User1\Downloads";
string destinationPath = System.IO.Directory.GetParent(pathAffected).FullName;
destinationPath = System.IO.Path.Combine(destinationPath, @"Viewed\");
Process vlcProcess = new Process();
vlcProcess.StartInfo.FileName = vlc;
vlcProcess.StartInfo.Arguments = "\"" + videoFile + "\"";
vlcProcess.StartInfo.Arguments += " --play-and-exit";
vlcProcess.Start();
vlcProcess.WaitForExit();
if (videoFile.IndexOf(pathAffected,
StringComparison.InvariantCultureIgnoreCase) >= 0)
{
System.IO.File.Move(videoFile,
System.IO.Path.Combine(destinationPath,
System.IO.Path.GetFileName(videoFile)));
if (IsSubfolder(pathAffected,
System.IO.Path.GetDirectoryName(videoFile)))
{
System.IO.Directory.Delete(
System.IO.Directory.GetParent(videoFile).FullName, true);
}
}
}
我发现IsSubfolder
的代码this question。
感谢您的好评,我已经授予您赏金!一个问题:如果VLC实际播放完整视频并自愿退出,是否有办法移动文件?就目前而言,如果我在视频中间关闭VLC,文件仍会移动。谢谢。 – 2013-02-16 03:52:11
感谢您的赏赐!我不知道来自VLC的信号表明它完成了整个视频。您可以尝试将其作为单独问题发布,并查看是否有人知道答案。 – endofzero 2013-02-16 04:30:56
嘿,我最近一直在使用这个程序,所以非常感谢!只有一件事,当视频与其他文件在一个子目录中时,其他文件被删除(好),但目录本身不会被删除。当我尝试在Windows中直接手动删除它时,出现文件处理问题。大约3-5秒后,我可以删除子目录。我怎样才能让你的解决方案完全工作?有没有办法等待目录上的句柄被释放?或者先关闭手柄?谢谢! – 2013-03-04 01:58:23