Windows 7 batch file to copy text file

I think you my want to ask this question on StackOverflow, as it does not pertain to InfinityFree.


This answer (edited) uses VBA, but Windows can support that:

Dim a1 As String = "C:\tmp\casefile.txt"
Dim b1 As String = "C:\tmp\returnfile.txt"
Dim aa1 As IO.StreamReader = IO.File.OpenText(a1)
Dim bb1 As IO.StreamWriter = IO.File.AppendText(b1)

Dim rr00 As String = aa1.ReadLine()
Do Until aa1.Peek() = -2
   rr00 = aa1.ReadLine()
   bb1.writeLine(rr00)
loop

https://social.msdn.microsoft.com/Forums/en-US/0438bbe2-3535-45b6-92fb-b3914dab198c/copy-text-except-first-line?forum=Vsexpressvb

You can also do this with PowerShell (get all files and write line 3+ to a file in %temp%\files with the same name):

Get-ChildItem -File | ForEach-Object {
    $stream_reader = New-Object System.IO.StreamReader{$_.FullName}
    $FileName = $_.Name
    $line_number = 3
    while (($current_line =$stream_reader.ReadLine()) -ne $null) {
        "$current_line" | Out-File -FilePath $env:TEMP\files\$FileName -Append
        $line_number++
    }
}
7 Likes