从一个目录复制到特定目的地。电源外壳
Copy from one directory to a specific destination. Powershell
这是我目前所掌握的。我觉得我需要对每个语句进行某种操作,或者将每个源行复制到从 csv 导入的每个目标行。想法?
$source = Import-Csv -header 'Source' C:\Test\source.csv
$destination = Import-Csv -header 'Dest' C:\Test\dest.csv
Copy-Item -Path $source -Destination $destination
回答问题:
文件:Source.csv
SourceFile
G:\Test\Excel\JPLTest-1.xlsx
G:\Test\Excel\JPLTest-A.xlsx
文件:Dest.csv
DestFile
G:\Test\Excel\JPLTest-2.xlsx
G:\Test\Excel\JPLTest-B.xlsx
代码:
$Source = Import-CSV -Path G:\BEKDocs\Scripts\Source.csv
$Dest = Import-CSV -Path G:\BEKDocs\Scripts\Dest.csv
#Note: If you use Santiago's suggestion you don't need this test!
If (($Source.Count) -ne ($Dest.Count)) {
"CSV File line counts do not match!"
} #End If
Else {
For ($Cntr = 0 ; $Cntr -lt $($Source.count) ; $Cntr++) {
Copy-Item -Path $($Source.SourceFile[$($Cntr)]) -Destination $($Dest.DestFile[$($Cntr)])
} #End For...
} #End Else
这是我目前所掌握的。我觉得我需要对每个语句进行某种操作,或者将每个源行复制到从 csv 导入的每个目标行。想法?
$source = Import-Csv -header 'Source' C:\Test\source.csv
$destination = Import-Csv -header 'Dest' C:\Test\dest.csv
Copy-Item -Path $source -Destination $destination
回答问题: 文件:Source.csv
SourceFile
G:\Test\Excel\JPLTest-1.xlsx
G:\Test\Excel\JPLTest-A.xlsx
文件:Dest.csv
DestFile
G:\Test\Excel\JPLTest-2.xlsx
G:\Test\Excel\JPLTest-B.xlsx
代码:
$Source = Import-CSV -Path G:\BEKDocs\Scripts\Source.csv
$Dest = Import-CSV -Path G:\BEKDocs\Scripts\Dest.csv
#Note: If you use Santiago's suggestion you don't need this test!
If (($Source.Count) -ne ($Dest.Count)) {
"CSV File line counts do not match!"
} #End If
Else {
For ($Cntr = 0 ; $Cntr -lt $($Source.count) ; $Cntr++) {
Copy-Item -Path $($Source.SourceFile[$($Cntr)]) -Destination $($Dest.DestFile[$($Cntr)])
} #End For...
} #End Else