powershell:For looponly loopin' 一次而不是多次



我读取一个CSV文件,其中包含多行信息,但是我的代码只执行CSV内容的第一行。如果我想用a打印出来write-host $dataFilesJS

对于CSV文件中的所有内容都可以正常工作。但是如果我想执行其他代码,它只循环一次。

我的源代码:

$CSV= Import-Csv \testtest.csv -Delimiter ';'
$csvFiles = $CSV 
$csvFiles.Count
for($i=0;$i -lt $csvFiles.count;$i++){
$filepathpdf = $csvFiles.filePathPdf[$i]
$filepathattachments = $csvFiles.filePathAttachments[$i]
$dataFilesJS= $csvFiles.dataFilesJS[$i]
$jsonFile= $csvFiles.jsonFile[$i]
$destinationFolderSave=$csvFiles.destinationFolderSave[$i]
$kategorieName=$csvFiles.kategorieName[$i]
New-Item -Path $destinationFolderSave -ItemType Directory
$foldersaves="_#_"
$sidepaths = New-Object System.Collections.Generic.List[System.Object]
$sidepathsAttachments= New-Object System.Collections.Generic.List[System.Object]
$children = Get-ChildItem $filepathpdf

$childrenAttachments= Get-ChildItem $filepathattachments

$childrensss = Get-ChildItem $filepathpdf/$children
$childrensssAttachments = Get-ChildItem $filepathattachments/$childrenAttachments

for($i=0;$i -le $childrensss.count;$i++){
$sidepaths.add($childrensss[$i])
}

for($i=0;$i -le $childrensssAttachments.count;$i++){
$sidepathsAttachments.add($childrensssAttachments[$i])
}
write-host $sidepathsAttachments

for($i=0;$i -lt $childrensss.count;$i++){
$childrenpath= $filepathpdf+"/"+$children+"/"+$sidepaths[$i]
$pdfchildren = Get-ChildItem $childrenpath
write-host $pdfchildren
Copy-Item $childrenpath/*  -Destination $destinationFolderSave -Recurse -force
}
}

这个很适合我:

$CSV= Import-Csv \testtest.csv -Delimiter ';'
$csvFiles = $CSV 
$csvFiles.Count
foreach($i in $csvFiles){
$filepathpdf = $i.filePathPdf
$filepathattachments = $i.filePathAttachments
$dataFilesJS= $i.dataFilesJS
$jsonFile= $i.jsonFile
$destinationFolderSave=$i.destinationFolderSave
$kategorieName=$i.kategorieName
New-Item -Path $destinationFolderSave -ItemType Directory
$foldersaves="_#_"
$sidepaths = New-Object System.Collections.Generic.List[System.Object]
$sidepathsAttachments= New-Object System.Collections.Generic.List[System.Object]
$children = Get-ChildItem $filepathpdf

$childrenAttachments= Get-ChildItem $filepathattachments

$childrensss = Get-ChildItem $filepathpdf/$children
$childrensssAttachments = Get-ChildItem $filepathattachments/$childrenAttachments

for($i=0;$i -le $childrensss.count;$i++){
$sidepaths.add($childrensss[$i])
}

for($i=0;$i -le $childrensssAttachments.count;$i++){
$sidepathsAttachments.add($childrensssAttachments[$i])
}
write-host $sidepathsAttachments

for($i=0;$i -lt $childrensss.count;$i++){
$childrenpath= $filepathpdf+"/"+$children+"/"+$sidepaths[$i]
$pdfchildren = Get-ChildItem $childrenpath
write-host $pdfchildren
Copy-Item $childrenpath/*  -Destination $destinationFolderSave -Recurse -force
}
}

相关内容

  • 没有找到相关文章

最新更新