1

I'm kind of new to PowerShell and I need to fix a bank statement file. The problem is that this file has a CNAB 240 standard, however, it comes with a line break, so we have to fix it manually.

I have a script that makes this correction, however, I can't make it run alone because I need to use CMD to run PowerShell. My idea is to use this script in the task manager to look for the .txt file and fix it, does anyone have any ideas?

Follow the script:

if ($args.count -eq 0)
{
    Write-Error "Please enter a file to read"
    return
}

$file = $args[0]

if(![System.IO.File]::Exists($file))
{
    Write-Error "File not found: $file"
    return
}

$expectedsize = 240
$lastSize = 0

foreach($line in [System.IO.File]::ReadLines($file))
{
    if ($line.length -gt 0)
    {
        if (!($row.length -eq $expectedsize) -And (($row.length + $lastSize) -eq $expectedsize))
        {
            Write-Host -NoNewLine $linha
            $lastSize += $line.length
        }
        else
        {
            if ($lastSize -gt 0)
            {
                Write-Host
            }
            Write-Host -NoNewLine $linha
            $lastSize = $line.length
        }
    }
    else
    {
        Write-Host
    }
}

The script above makes the normal correction of the file, however, I am not able to make it follow the steps below:

  • Browse the txt file
  • Validate that it does not have the 240 positions in each line
  • And then make the correction

0 Answers0