Link to home
Start Free TrialLog in
Avatar of _Sparky
_SparkyFlag for Ireland

asked on

Need to Produce an Executable file that will strip the first two lines from a dat file

I have accountin software that produces a .dat file for BACS transmission.  We have a new bank (& new BACS type) that can't accept our current file format.

The only issuse with the file is two header lines (the first two lines of the file) need to be removed, it's then transmitted to the bank using standard polling software  - the process is done by the user (based in a different country).

I need to be able to create an executable file (dos batch/compiled exe etc) that will allow
-browse to file (file is usually FTP'd from accounting software server to c:\temp, but that could be variable)
-the .dat filename can also be variable
-Remove the first 2 lines from the file (lines aren't numbered, or unique in any way)
-Save the file with original filename & preserve all other formatting
-The user should not "see" the file content during the process
-& finally open the polling software for bank transmission (again, it's location could be variable, but that should just be a small code change before it's compiled to install on users desktop)

I've searched some the the current solutions for this, but most involve the user either needing (for instance) some kind of dev software & "seeing" whats happening - I need the process to "look" completely automatic.

Can anyone help me get started?

Many thanks,
Avatar of Pacman
Pacman
Flag of Germany image

To remove the first 2 lines you could read from file A and write to file B (skipping the first 2 lines).
When finished and everything is ok, the delete file A (or rename it to A.ori) and then rename file B to file A.
Then launch your polling software.
Avatar of matrixnz
matrixnz

Hi Sparky

Try this, download and install AutoIT v3 http://www.autoitscript.com/autoit3/downloads.shtml also recommend downloading and installing AutoIt Script Editor found on the same page.

Description - AutoIt v3 is a freeware BASIC-like scripting language designed for automating the Windows GUI and general scripting.

Once downloaded and installed open the AutoIT Script Editor (Scite) copy and paste the attached code snippet and save the file for instance C:\Data\RemLine.au3.  Now within Scite click Tools - Build this will create an executable in the same folder that you saved the .au3 file, it will be named RemLine.exe if you use the naming convention suggested.

Simply run.

What it does will give you an Open Dialog box, the initial directory will be %temp%
You will only be able to select .dat files
Once Selected, it will than create an array of the entire file it then rewrites the file back removing the first two lines.

Hope that helps.

Cheers
#NoTrayIcon
#include <file.au3>
 
Dim $DAT_ARYFILE
 
$DAT_SELFILE = FileOpenDialog('Please Select a file', @TempDir, 'Dat Files(*.dat)', 4)
If @error Then
    MsgBox(48, 'File Selection Error', 'No File(s) selected                         ')
	Exit
EndIf
 
If Not _FileReadToArray($DAT_SELFILE, $DAT_ARYFILE) Then
   MsgBox(48, 'Error', ' Error reading ' & @CRLF & @CRLF & $DAT_SELFILE & '          ' & @CRLF & @CRLF & 'Error:' & @error)
   Exit
EndIf
 
$DAT_OPNFILE = FileOpen($DAT_SELFILE, 2)
	If $DAT_OPNFILE = -1 Then
		MsgBox(48, 'Error', 'Unable to open:' & @CRLF & $DAT_SELFILE & '          ')
		Exit
	EndIf
 
	FileWriteLine($DAT_OPNFILE, '')
	FileWriteLine($DAT_OPNFILE, '')
 
	For $x = 3 to $DAT_ARYFILE[0]
		FileWriteLine($DAT_OPNFILE, $DAT_ARYFILE[$x])
	Next
 
FileClose($DAT_OPNFILE)

Open in new window

Avatar of _Sparky

ASKER

Hi

Thanks for that - The AutoIT tool is a great feature - going to be spending a lot time playing with that!

Just one question on the code - The file is being left with two blank lines at the top (I assume the code FileWriteLine is causing that)

Is there a way of deleting these altogether?
ASKER CERTIFIED SOLUTION
Avatar of matrixnz
matrixnz

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of _Sparky

ASKER

Many thanks for the help - Great script tool too!