0
我試圖在PowerShell中組合字符串來生成文件路徑。我學習的基本知識,並已經把這個語法Powershell添加空間
$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)\
}
但是,當我Write-Host
存在的文件路徑的空間。輸出是
E:\Main Folder\ 2016 \
我該如何刪除空間?我嘗試使用Trim()
運營商,但空間仍然存在。
查找到聯接路徑和拆分路徑。 –
@KoryGill - 感謝您指點正確的方向! – BellHopByDayAmetuerCoderByNigh