In Windows, after double-clicking a video file, when it's finished, I want the file to be moved up a dir or 2, and any containing folder deleted.

I only want this to affect files located in C:\Users\User1\Downloads, say %x%.

There are 2 scenarios:

  1. If the file is %x%\Training.4273865.2013.avi, it should be moved to ..\Viewed\.

  2. If the file is %x%\Showcase\SomeFile.mp4, it should be moved to the same folder: ..\..\Viewed\. The Showcase folder should then be deleted. Currently, I have to close VLC (to close the file handle) before Showcase (and it's other contents) can be deleted.

A solution would be good, but I don't mind any language I can compile with or similar open-source compiler.

有帮助吗?

解决方案

Here is an example C# application that can do what you're asking. Launch it by right clicking a video file, choosing Open With, and selecting the C# application's executable (you can check the box for "Always use the selected program to open this kind of file" to make the change permanent).

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);
        }
    }

}

I found the code for IsSubfolder in this question.

其他提示

You could write a wrapper and associate it with your media files.

Which would indirectly launch VLC and then move files about once it closes.

VLC takes a list of streams as arguments, append vlc://quit to the end of your playlist to automatic exit VLC.

A wrapper written in C# would be more flexible, but here's a quick example in batch.

set VLC=C:\Program Files\VideoLAN\VLC\vlc.exe
set FILE=Tig Notaro - Live.mp3
start "VLC" /WAIT "%VLC%" "%FILE%" vlc://quit
echo VLC has closed, I can move the file.
move "%FILE%" old/
pause
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top