2

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.

Danny Beckett
  • 20,529
  • 24
  • 107
  • 134

2 Answers2

3

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
  • Thanks for the answer William! I know I said a [tag:c#] or [tag:batch] solution would be good, but the [tag:c#] solution is, as you said, more flexible. Thanks for the effort! – Danny Beckett Feb 15 '13 at 23:14
3

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.

Community
  • 1
  • 1
endofzero
  • 1,830
  • 1
  • 22
  • 33
  • Thank for the great answer, I've awarded you the bounty! One question: is there a way to only move the file if VLC actually played the full video and voluntarily exited? As it stands, if I close VLC in the middle of a video, the file is moved anyway. Thanks. – Danny Beckett Feb 16 '13 at 03:52
  • Thanks for the bounty! I am not aware of a signal from VLC that indicates it completed the entire video. You might try posting that as a separate question and see if someone out there knows the answer. – endofzero Feb 16 '13 at 04:30
  • Hey, I've been using this program a lot recently, so thanks a lot for it! Just one thing, when the video is in a subdir with other files, the other files get deleted (good), but the dir itself isn't deleted. When I try to manually delete it in Windows straight after, I get a file handle problem. About 3-5 seconds later, I can delete the subdir. How can I make your solution work fully? Is there a way to wait for the handle on the dir to be released? Or close the handle first? Thanks! – Danny Beckett Mar 04 '13 at 01:58