Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parse And Save

Status
Not open for further replies.

devangelista

Technical User
May 14, 2002
12
US
Hello QBasic Guru's

I've searched the threads a bit and have some idea of how to do this but I can't seem to get it right.

Here's what I'm trying to do:

I receive files from the Federal Reserve Bank in the following format: AHMMDDXI.001 or AHMMDDXI.002

Inside these files are header records at positions 1 - 13, a sample header is: 101 083901825

I need to parse all files in a directory that have either .001 or .002 extensions, examine the file header and evaluate the "083901825" part and based on what it is save the file AHMMDDXI.001 or .002 as another file name, move the original source file to an archive location, and repeat this for every file in the directory.

For Example:
Input File: AHMMDDXI.001
If Header Rec: 101 083901825
Then Output File: AHMMDDXI.ALT
Else If Header Rec: 101 061308770
Then Output File: AHMMDDXI.FED
Move or archive: AHMMDDXI.001 to hard coded Location

Repeat for each file in the directory.

Any assistance would be greatly appreciated. We are despirate...

Best Regards

David Evangelista
FiNET, Inc.
 
First, put a directory of the files you want to work with in a file:

SHELL "dir/b/-p/-w *.001 > frb.txt"
SHELL "dir/b/-p/-w *.002 >> frb.txt"

Open the file for sequential reading and follow the line of this mixture of pseudocode and QBASIC:

DO WHILE NOT EOF(the directory file number)
Read a file name in
Open that file for the next number for binary
Read the first 13 characters into a variable
Close this file
SELECT CASE first 13 characters
CASE "101 083901825"
outfileextension$ = "alt"
movedirectory$ = Hard coded move directory
CASE "101 061308770"
outfileextension$="fed"
movedirectory$ = Hard coded move directory
END SELECT
filenameroot$= LEFT$(file name, INSTR(file name, "."))
outfile$ = Hard coded move directory + "\" + filenameroot$ + outfileextension$
SHELL "copy " + filename + " " + outfile$
KILL file name
LOOP

CLOSE
 
Many Thanks trollacious. I have made a combination of the code outlined above and I have resolved the problem.

If it were not for your generous posting, I would have never completed this project!!

Thank you for all your help...

David Evangelista
FiNET, Inc.


Here is what I finally wote:

CLS
DIM FileLen AS INTEGER
DIM Exists AS INTEGER
DIM LogFileLen AS INTEGER
Fedloc$ = "C:\Fedline2\ah\prod\"
FedArc$ = "C:\Fedline2\ah\prod\archive\"
ON ERROR RESUME NEXT
KILL Fedloc$ + "frb.dat"
KILL Fedloc$ + "exists.dat"
SHELL "dir " + Fedloc$ + "*.0*/b/-p/-w > " + Fedloc$ + "frb.dat"
FileName$ = Fedloc$ + "frb.dat"
OPEN FileName$ FOR INPUT AS #1
OPEN "LPT1" FOR OUTPUT AS #3
PRINT #3, "==========================================================="
PRINT #3, " FEDLINE INCOMING FILE PROCESSOR LOG FILE "
PRINT #3, " (C) 2002 ALL RIGHTS RESERVED "
PRINT #3, " FiNET, Inc. "
PRINT #3, SPC(20); DATE$ + " " + TIME$
PRINT #3, "==========================================================="
PRINT #3, " "
PRINT #3, " "
DO
LINE INPUT #1, FileName$
DayRange$ = MID$(FileName$, 3, 4)
FileType$ = MID$(FileName$, 7, 1)
FileExt$ = RIGHT$(FileName$, 2)
FileLen = LEN(FileName$)
FileLen = FileLen - 4
NewFileName$ = LEFT$(FileName$, FileLen)
OPEN Fedloc$ + FileName$ FOR INPUT AS #2
LINE INPUT #2, Detail$
Detail$ = LEFT$(Detail$, 13)
SELECT CASE RIGHT$(Detail$, 9)
CASE "083950009"
SHELL "copy " + Fedloc$ + FileName$ + " " + Fedloc$ + "A" + DayRange$ + FileType$ + FileExt$ + ".txt > nul"
PRINT #3, "Copied: " + FileName$ + " To: " + "A" + DayRange$ + FileType$ + FileExt$ + ".txt ## ALLOT FILE ##"
SHELL "copy " + Fedloc$ + FileName$ + " " + FedArc$ + FileName$ + " > nul"
PRINT #3, " Moved: " + FileName$ + " To: " + FedArc$ + FileName$
PRINT #3, " "
CLOSE #2
CASE "061308770"
SHELL "copy " + Fedloc$ + FileName$ + " " + Fedloc$ + "F" + DayRange$ + FileType$ + FileExt$ + ".txt > nul"
PRINT #3, "Copied: " + FileName$ + " To: " + "F" + DayRange$ + FileType$ + FileExt$ + ".txt ## FEDSYS FILE ##"
SHELL "copy " + Fedloc$ + FileName$ + " " + FedArc$ + FileName$ + " > nul"
PRINT #3, " Moved: " + FileName$ + " To: " + FedArc$ + FileName$
PRINT #3, " "
CLOSE #2
END SELECT
LOOP UNTIL EOF(1)
CLOSE #1
SHELL "DIR " + Fedloc$ + "*.TXT/b/-p/-w > " + Fedloc$ + "exists.dat"
OPEN Fedloc$ + "exists.dat" FOR INPUT AS #4
LINE INPUT #4, FILELINE$
LogFileLen = LEN(FILELINE$)
IF LogFileLen = 0 THEN
PRINT "There Were No Incoming File(s) to process. Exiting!"
PRINT #3, " There Were No Incoming File(s) to process. Exiting!"
CLOSE #4
ELSE
CLOSE #4
END IF
CLOSE #3
PRINT "Please Check Your Printer For File Process Details!"
KILL Fedloc$ + "exists.dat"
KILL Fedloc$ + "*.0*"
KILL Fedloc$ + "frb.dat"
SYSTEM


ANYONE VIEWING THIS POST IS FREE TO USE THE ABOVE CODE WITH CONSENT OF FiNET, Inc.

Thanks Again Tek-Tips!!!


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top