我需要在 Powershell 控制台中显示 $FileNames 数组的所有元素。我正在 For 循环中进行迭代,但无法将双引号打印到控制台上的所有数组索引元素。请帮忙。
实际结果: 已删除文件:- “$FileNames[$i]”已成功放入文件夹
带双引号的预期结果(对于数组中的每个文件名): 删除文件:-“NewFile1.txt”成功放入文件夹...依此类推。
$FileNames = @(Get-ChildItem $TestFolder\*.txt | Select-Object -ExpandProperty Name)
For($i=0;$i -lt $FileNames.count;$i++)
{
if($FileNames[$i] -eq $fileName)
{
$filePathNew = $TestFolder + $FileNames[$i]
Copy-Item -Path $filePathNew -Destination $RemoteURLFolder\$FolderName -Recurse
Write-Host "=> Dropped file:- "'"$FileNames[$i]"'" successfully into the folder ""
您可以使用:
Write-Host "=> Dropped file:- `"$($FileNames[$i])`" successfully into the folder"
所做的更改:
`
。$FileNames[$i]
),您可以
将其扭曲成 $()
。另请参阅