Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy From dbf fields file to another dbf #35

Open
djjatoro opened this issue Nov 30, 2024 · 0 comments
Open

Copy From dbf fields file to another dbf #35

djjatoro opened this issue Nov 30, 2024 · 0 comments

Comments

@djjatoro
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant