I am attempting to combine strings in powershell to generate a file path. I am learning the basics and have put together this syntax
$fileDirectory = "C:\Pics\"
foreach ($file in Get-ChildItem $fileDirectory){
#Setting parent dir to check
$ParentDir = "E:\Main Folder\"
#setting param to split
$parts =$file.Name -split '\.'
#capturing variables
$PictureYear = $parts[0].Trim()
$PictureMonth = $parts[1].substring(0,3)
#Writing To window to confirm variables are accurate
Write-Host $PictureYear
Write-Host $PictureMonth
#checking if folders exist
Write-Host $($ParentDir)$($PictureYear)\
}
But when I Write-Host there is a space in the filepath. The output is
E:\Main Folder\ 2016 \
How can I remove the space? I tried using the Trim() operator but the space still exists.