【发布时间】:2016-08-28 05:30:40
【问题描述】:
我有一个问题。 我创建了一个带有文件名、源目录和目标目录的格式表。 现在我尝试用 foreach 遍历表。 在这个循环中,我想将文件从源目录移动到目标目录。我的问题是从行中获取项目。
这是我的示例代码:
cls
$MovePathSource = "C:\Users\user\Desktop\sourcefolder"
$MovePathDestination = "C:\Users\user\Desktop\destinationfolder"
$filetypes = @("*.llla" , "html")
$table = dir $MovePathSource -Recurse -Include $filetypes | Format-Table@{Expression={$_.Name};Label="Filename"},@{Expression={($_.DirectoryName)};Label="Sourcepath"},@{Expression={($_.DirectoryName).Replace($MovePathSource,$MovePathDestination)};Label="Destinationpath"}
$table
foreach ($row in $table)
{
write-host "$row.Sourcepath"
#Move-Item -Path ($row.Sourcepath + "\" + $row.Filename) -Destination $row.Destinationpath
}
【问题讨论】:
标签: powershell foreach formattable