Fix for LiteralPath in movie-files causing error

This commit is contained in:
Michael Reber 2020-03-25 23:27:09 +01:00
parent 92f7605c41
commit 3c91c0d78f

View File

@ -24,7 +24,7 @@ if(!(Test-Path $NVEncoder -PathType leaf))
} }
# Get video list from provided path: # Get video list from provided path:
$videos = Get-ChildItem -Path $videoPath -Name -Recurse -Include ('*.mp4', '*.mkv') #('*.avi', '*.mp4', '*.mkv') - avi currently doesn't work. $videos = Get-ChildItem -LiteralPath $videoPath -Name -Recurse -Include ('*.mp4', '*.mkv') #('*.avi', '*.mp4', '*.mkv') - avi currently doesn't work.
# Instantiating used variables: # Instantiating used variables:
$videoID = 1 $videoID = 1
@ -49,6 +49,10 @@ Function LogWrite
} }
# Create new log directory: # Create new log directory:
New-Item -itemType Directory -Path $PSScriptRoot\logs\ -Name $logFolderName > $null New-Item -itemType Directory -Path $PSScriptRoot\logs\ -Name $logFolderName > $null
# Calculates the total size of the given directory in GB:
Write-Host "Inizialization in progress.."
$folderSizeInGB = "{0:N2} GB" -f ((Get-ChildItem $videoPath -Recurse | Measure-Object -Property Length -Sum -ErrorAction Stop).Sum / 1GB)
Clear-Host # Clears the upper message from the window
############################################################################################################# #############################################################################################################
# END - Testing and conversion preparations # END - Testing and conversion preparations
@ -57,7 +61,7 @@ New-Item -itemType Directory -Path $PSScriptRoot\logs\ -Name $logFolderName > $n
############################################################################################################# #############################################################################################################
# Main conversion process # # Main conversion process #
############################################################################################################# #############################################################################################################
Write-Host "Found $count videos. - starting converter.." -ForegroundColor Cyan Write-Host "Found $count videos with a total size of $folderSizeInGB - starting converter.." -ForegroundColor Cyan
Write-Host Write-Host
Write-Host Write-Host
Write-Host "------------------------------------------------------------------------------------------------" Write-Host "------------------------------------------------------------------------------------------------"
@ -113,7 +117,9 @@ foreach($video in $videos)
Wait-Process -Id $processID Wait-Process -Id $processID
if(Test-Path $outputFile) if(Test-Path -LiteralPath $outputFile)
# Specifies a path to be tested. Unlike Path, the value of the LiteralPath parameter is used exactly as it is typed.
#No characters are interpreted as wildcard characters.
{ {
Write-Host "CONVERSION DONE! FILE: `"$outputFile`" FOUND" -ForegroundColor Yellow Write-Host "CONVERSION DONE! FILE: `"$outputFile`" FOUND" -ForegroundColor Yellow
Start-Sleep -Seconds 4 Start-Sleep -Seconds 4
@ -135,7 +141,7 @@ foreach($video in $videos)
Write-Host "Conversion Successful! - Deleting old file.." Write-Host "Conversion Successful! - Deleting old file.."
Write-Host Write-Host
Write-Host "------------------------------------------------------------------------------------------------" Write-Host "------------------------------------------------------------------------------------------------"
Remove-Item -Path $inputFile Remove-Item -LiteralPath $inputFile
$convertedVideos = $convertedVideos + 1 $convertedVideos = $convertedVideos + 1
$Logfile = "$PSScriptRoot\logs\$logFolderName\successfully_converted.log" $Logfile = "$PSScriptRoot\logs\$logFolderName\successfully_converted.log"
LogWrite "$outputFile" LogWrite "$outputFile"
@ -145,7 +151,7 @@ foreach($video in $videos)
Write-Host "Conversion Failded! - Deleting new converted file.." -ForegroundColor Red Write-Host "Conversion Failded! - Deleting new converted file.." -ForegroundColor Red
Write-Host Write-Host
Write-Host "------------------------------------------------------------------------------------------------" Write-Host "------------------------------------------------------------------------------------------------"
Remove-Item -Path $outputFile Remove-Item -LiteralPath $outputFile
$failedVideos = $failedVideos + 1 $failedVideos = $failedVideos + 1
$notConvertedVideos = $notConvertedVideos + 1 $notConvertedVideos = $notConvertedVideos + 1
$Logfile = "$PSScriptRoot\logs\$logFolderName\error_during_conversion.log" $Logfile = "$PSScriptRoot\logs\$logFolderName\error_during_conversion.log"
@ -178,6 +184,8 @@ foreach($video in $videos)
############################################################################################################# #############################################################################################################
# Evaluation part of the conversion script # # Evaluation part of the conversion script #
############################################################################################################# #############################################################################################################
Write-Host "Final calculations are in progress.."
$folderSizeInGB2 = "{0:N2} GB" -f ((Get-ChildItem $videoPath -Recurse | Measure-Object -Property Length -Sum -ErrorAction Stop).Sum / 1GB)
if($notConvertedVideos -eq 0) if($notConvertedVideos -eq 0)
{ {
Write-Host "Finished converted $convertedVideos out of $count videos." -ForegroundColor Green Write-Host "Finished converted $convertedVideos out of $count videos." -ForegroundColor Green
@ -193,6 +201,8 @@ if($notConvertedVideos -eq 0)
} }
} }
Write-Host "Directory size before conversion: $folderSizeInGB"
Write-Host "Directory size after conversion: $folderSizeInGB2"
Read-Host -Prompt "Press Enter to exit" Read-Host -Prompt "Press Enter to exit"
############################################################################################################# #############################################################################################################