在 Windows 中,双击视频文件后,完成后,我希望将文件向上移动一个或两个目录,并删除任何包含的文件夹。
我只想影响位于 C:\Users\User1\Downloads
的文件,比如说%x%
.
有两种情况:
如果文件是
%x%\Training.4273865.2013.avi
,应移至..\Viewed\
.如果文件是
%x%\Showcase\SomeFile.mp4
,应将其移至同一文件夹:..\..\Viewed\
。Showcase
然后应该删除文件夹。目前,我必须在Showcase
之前关闭VLC(以关闭文件句柄) (及其其他内容)可以删除。
一个c#解决方案会很好,但我不介意可以使用 visual-studio-2012 编译任何语言或类似的开源编译器。
最佳答案
这是一个示例 C# 应用程序,可以满足您的要求。右键单击视频文件,选择“打开方式”,然后选择 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);
}
}
}
我在 this question 中找到了 IsSubfolder
的代码.
关于c# - VLC:将文件移动到末尾,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14841724/