Monthly Archives: August 2017

Powershell if file does not exist

Small gotcha that caught me recently, I needed to do a test-path but action if a file did NOT exist, and I had trouble getting it to work first go, so I’m writing this here:

$FileToCheck="c:\windows\system32\notepad.exe"
## check file exists
if (!(Test-Path $FileToCheck))
{
     throw "$FileToCheck not found"
}

This will throw the exception if the file can not be found.

Batch converting video combining FFMpeg and Powershell

I had a bunch of MKV files that I needed to convert to mp4.  I don’t have any fancy video editing software, and found that a program called ffmpeg exists, which is a command line tool that will do this.  Once I verified that it would do what I wanted, I decided to write a powershell script that will do the work for me, which you can find here.

You will need to download and install ffmpeg and run the script.  I have defaulted ffmpeg to “c:\program files\ffmpeg\ffmpeg.exe” as this seems like the logical place for me.

If you have any comments, or ideas on how to improve, please let me know in the comments below.