c# - VLC:将文件移动到末尾

标签 c# .net vlc libvlc vlcj

在 Windows 中,双击视频文件后,完成后,我希望将文件向上移动一个或两个目录,并删除任何包含的文件夹。

我只想影响位于 C:\Users\User1\Downloads 的文件,比如说%x% .

有两种情况:

  1. 如果文件是 %x%\Training.4273865.2013.avi ,应移至..\Viewed\ .

  2. 如果文件是 %x%\Showcase\SomeFile.mp4 ,应将其移至同一文件夹:..\..\Viewed\Showcase然后应该删除文件夹。目前,我必须在Showcase之前关闭VLC(以关闭文件句柄) (及其其他内容)可以删除。

一个解决方案会很好,但我不介意可以使用 编译任何语言或类似的开源编译器。

最佳答案

这是一个示例 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/

相关文章:

.net - 实体数据模型 - 导出到 Visual Studio 中的其他解决方案

c# - 我需要删除这种事件处理程序吗?

FFMPEG 流媒体错误 : Failed to update header with correct filesize and duration

c# - UI 不更新 ExpandoObject 列表

c# - 如何计算特定操作(预定义功能)需要完成的时间?

c# - 扩展方法必须在非通用静态类中定义

c# - 单击以打开项目(指向选择)

c# - 在网格布局中创建动态按钮 - 创建幻方 UI

lua - 如何在vlc Lua扩展脚本中获取当前播放时间

ffmpeg - 如何从 MP4 文件中提取元数据轨道