Last active
May 9, 2019 01:04
-
-
Save jaredhaight/c8d3c6f71c8687cea5bc9485eddd7588 to your computer and use it in GitHub Desktop.
Get Total Length of Time from a Directory of Videos
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Stolen from here: https://social.technet.microsoft.com/Forums/en-US/bad2dbb1-5deb-48b8-8f8c-45e2b353dba0/how-do-i-get-video-file-duration-in-powershell-script?forum=winserverpowershell#de6ee12a-1c1e-474f-b5ba-ece4b17e0144 | |
function Get-VideoLength { | |
param ( | |
$Path | |
) | |
if (-not $Path) { | |
$Path = (Get-Location).Path | |
} | |
$videos = Get-ChildItem $Path | |
$objShell = New-Object -ComObject Shell.Application | |
$folder = $objShell.NameSpace($Path) | |
[timespan]$TotalTime = '00:00:00' | |
forEach ($video in $videos) { | |
$objFile = $folder.ParseName($video.Name) | |
$TotalTime += [timespan]$folder.GetDetailsOf($objFile, 27) | |
} | |
$TotalTime | Select-Object Days, Hours, Minutes, Seconds | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment