The QBasic / QB64 Discussion Forum      Other Subforums, Links and Downloads
 
 Return to Index  

SemiZIP - merge ASCII files for posting on forum & vv.

September 17 2005 at 10:52 AM
  (Premier Login iorr5t)
Forum Owner

CONST Source1 = "http://www.network54.com/Forum/thread?"
CONST Source2 = "forumid=190883&messageid=1126979543"

CONST Delim = "=============<<<Delimiter>>>=============="
DIM MyErr AS INTEGER
GOSUB InitialScreen
GOSUB DoWork
SYSTEM

GetMyErr:
MyErr = ERR
RESUME NEXT

Split:
OPEN fleZIP$ FOR INPUT AS #1
DO WHILE NOT EOF(1)
  LINE INPUT #1, l$
  IF l$ = Delim THEN EXIT DO
LOOP
IF l$ <> Delim THEN PRINT fleZIP$; " has the wrong format": RETURN
DO
  LINE INPUT #1, l$
  MyErr = 0: ON ERROR GOTO GetMyErr
  OPEN l$ FOR OUTPUT AS #2
  ON ERROR GOTO 0
  IF MyErr > 0 THEN
    PRINT l$; " is an illegal file name"
    RETURN
  END IF
  PRINT l$
  IF NOT EOF(1) THEN LINE INPUT #1, l$
  DO WHILE NOT EOF(1)
    LINE INPUT #1, l$
    IF l$ = Delim THEN EXIT DO
    PRINT #2, l$
  LOOP
  CLOSE #2
LOOP WHILE NOT EOF(1)
CLOSE #1
RETURN

Merge:
OPEN fleZIP$ FOR APPEND AS #2
DO: GOSUB Merge1: LOOP UNTIL TimeToStop
CLOSE
RETURN
Merge1:
LINE INPUT "Name of file to merge: "; fleIn$
IF fleIn$ = "" THEN TimeToStop = -1: RETURN
MyErr = 0: ON ERROR GOTO GetMyErr
OPEN fleIn$ FOR INPUT AS #1
ON ERROR GOTO 0
IF MyErr > 0 THEN PRINT "   Not found: "; fleIn$: RETURN
PRINT #2, Delim
PRINT #2, fleIn$
PRINT #2, STRING$(LEN(fleIn$), "-")
WHILE NOT EOF(1): LINE INPUT #1, l$: PRINT #2, l$: WEND
CLOSE #1
PRINT "   Successfully included "; fleIn$
RETURN

DoWork:
DO
  LINE INPUT "Merge or Split? M/S: ", a$: IF a$ = "" THEN RUN
  IF LEN(a$) = 1 THEN
    a$ = UCASE$(a$)
    IF INSTR("MS", a$) > 0 THEN EXIT DO
  END IF
LOOP
IF a$ = "M" THEN
  IF GotFile THEN
    PRINT fleZIP$; " already exists"
    DO
      LINE INPUT "Overwrite, Append, Restart O/A/R: "; a$
      IF a$ = "" THEN RUN
      IF LEN(a$) = 1 THEN
        a$ = UCASE$(a$)
        IF INSTR("OAR", a$) > 0 THEN EXIT DO
      END IF
    LOOP
    IF a$ = "R" THEN RUN
    IF a$ = "O" THEN GOSUB StartNew
  ELSE
    GOSUB StartNew
  END IF
  GOSUB Merge
  RETURN
END IF
IF GotFile THEN GOSUB Split: RETURN
PRINT fleZIP$; " does not exist. Press key to restart"
DO: LOOP WHILE INKEY$ = ""
RUN

StartNew:
OPEN fleZIP$ FOR OUTPUT AS #2
PRINT #2, "Either manually create all the files below, using the"
PRINT #2, "file names given, or create a single text file with"
PRINT #2, "a name not used below and run this utility:"
PRINT #2, Source1 + Source2
PRINT #2, ""
CLOSE
RETURN

InitialScreen:
CLS
LOCATE 2, 30: PRINT "S E M I - Z I P"
PRINT : PRINT "At any time, just press Enter when finished"
PRINT
DO
  LINE INPUT "Name of SemiZip file: ", fleZIP$
  IF fleZIP$ = "" THEN SYSTEM
  MyErr = 0: ON ERROR GOTO GetMyErr
  OPEN fleZIP$ FOR INPUT AS #1
  ON ERROR GOTO 0: CLOSE
  IF MyErr = 53 THEN GotFile = 0: RETURN
  IF MyErr = 0 THEN GotFile = -1: RETURN
LOOP




    
This message has been edited by iorr5t on Sep 18, 2005 10:45 AM
This message has been edited by iorr5t on Sep 18, 2005 10:43 AM


 
 Respond to this message   
Response TitleAuthor and Date
I'm having some problems with your program. (View Thread) on Sep 17
You need a file that has been built. (View Thread)Mac on Sep 17
   * Thanks, I thought it was a file splitter :P. on Sep 17
      New name for it: "SemiZIP" on Sep 18

Newbies usually go to www.qbasic.com and click on The QBasic Forum
Forum regulars have their own ways, which include The QBasic Community Forums