Description
Hello,
Please, I wanted to ask you the following question:
I am trying to make a copy of the records from a dbf file -visualfoxpro- (with records) using PowerShell to another with the same structure but with empty content.
I would like to use the dBase.NET library, but I can't find a way.
Would you be so kind as to give me some suggestions?
Here is the code:
$SourceO = "C:\Users\jantd\Desktop\articulo.dbf" # dbf file Origin
$SourceD = "C:\Users\jantd\Desktop\articulo1.dbf" # dbf file Destiny
$dll = "$PSScriptRoot\dBASE.NET.dll" # Assembly
$BaseNameO = (Get-Item $SourceO).BaseName
$Count = $null
$Assembly = [Reflection.Assembly]::LoadFile("$dll") # Load Assembly
$dbfO = New-Object dBASE.NET.Dbf # Load class
$dbfO.Read($SourceO) # Read dbf file's content
$HeadersO = $dbfO.Fields.name
$RecordsO = $dbfO.Records
$DataO = $RecordsO.Data
$ColNumO = $HeadersO.Count
$dbfD = New-Object dBASE.NET.Dbf # Load class
$dbfD.Read($SourceD) # Read dbf file's content
$HeadersD = $dbfD.Fields.name
$RecordsD = $dbfD.Records
$DataD = $RecordsD.Data
$ColNumD = $HeadersD.Count
foreach ($Row in $dbfO.Records) {
$dbfD.CreateRecord()
#for ($i=0;$i -lt 10;$i++){
#$dbfD.Data. [$i] = $row.Data[$i]
#Write-Host $i - $Row.data[$i]
#Write-Host $i - $dbfD.Records.d
# $newRecord.Data.Add($row[$i].data)
# Write-Host $row[$i]
# Write-Host $newRecord.Data.ToArray()
#if ($newRecord[$i].name -eq $row[$i].name) {
# $newRecord.Fields.name[0].data = $Row[$i].data
#}
#}
}
$dbfVersion = New-Object dBASE.NET.DbfVersion
$dbfVersion = [dBASE.NET.DbfVersion]::VisualFoxProWithAutoIncrement
$dbfP.Write($SourceP, $dbfVersion)
Thank you.