Announcement

Collapse
No announcement yet.

Backing Up Files to more than 1 disk

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Backing Up Files to more than 1 disk

    How do I get powerbasic to back up files to more than one disk, if the first disk is full?
    I wrote this code:
    shell "copy class.txt a:\"
    The size of class.txt is 1.57 mbytes.
    The computer responds with disk full.
    "How do I get it to ask me to insert another disk to complete
    the copy process?
    Thanks,
    Keith



  • #2
    Since your file exceeds the size of a single floppy, you have to break it into smaller chunks. You can use pkzip with its disk spanning function, or do it yourself programmatically.

    These are 2 programs I wrote a while ago to do this.
    Code:
    ' To Span:
    '***********
    SPAN.BAS
    $STRING 32  ' 32750 bytes
    $COMPILE EXE
    $INCLUDE "PB32.INC"  ' use PB32 library
    
    IF ArgC(COMMAND$) < 3 THEN
      CALL Usage
    END IF
    tDrive$ = ArgV$(1, COMMAND$)
    IF LEN(tDrive$)<2 THEN tDrive$ = tDrive$ + ":"
    inFile$ = ArgV$(2, COMMAND$)
    outFile$ = ArgV$(3, COMMAND$)
    IF LEN(DIR$(inFile$))< 1 THEN
      PRINT "Input File Name does not exist!"
      CALL Usage
    END IF
    
    temp = INSTR(outFile$,".")
    IF temp = 1 THEN CALL Usage
    IF temp > 1 THEN outFile$ = LEFT$(outFile$,temp-1)
    outFile$ = LEFT$(outFile$,8)
    
    ON ERROR GOTO ErrorHandler
    ihandle? = FREEFILE
    OPEN inFile$ FOR BINARY AS ihandle?
    inLen& = LOF(ihandle?)
    ncount% = 1
    tFile$ = tDrive$ + outFile$ + ".s01"
    ohandle? = FREEFILE
    OPEN tFile$ FOR BINARY AS ohandle?
    freeSpc??? = DISKFREE(LEFT$(tDrive$, 1))
    inbytes& = MIN(32256, inLen&, freeSpc???)
    DO
      GET$ ihandle?,inbytes&, buffer$
      DECR inLen&, inbytes&
      PUT$ ohandle?, buffer$
      DECR freeSpc???, inbytes&  ' Keep track of space available on drive
      inbytes& = MIN(32256, inLen&)
      IF freeSpc??? < inbytes& THEN
        CLOSE # ohandle?  ' first close file on disk
    ' Prompt to insert disk
        CLS
        PRINT " Current Disk Full!"
        PRINT
        PRINT " Insert New Disk"
        PRINT
        PRINT " press any key to continue."
        WHILE INSTAT
          i$ = inkey$
        WEND  ' empty keyboard buffer
        WHILE NOT INSTAT : WEND
        CLS
    
        INCR ncount%, 1
        temp$ = LTRIM$(STR$(ncount%))
        IF LEN(temp$) < 2 THEN temp$ = "0" + temp$
        tFile$ = tDrive$ + outFile$ + ".s" + temp$
        OPEN tFile$ FOR BINARY AS ohandle?
        freeSpc??? = DISKFREE(LEFT$(tDrive$, 1))
        inbytes& = MIN(32256, inLen&, freeSpc???)
      END IF
    
      IF inbytes& < 1 THEN EXIT LOOP
    LOOP
    
    PRINT "Finished!"
    CLOSE
    END
    
    ErrorHandler:
      CLOSE
      PRINT "Drive Not Ready!"
      END
    
    SUB Usage
      PRINT
      PRINT "  Usage: Span <drive> <inputName> <outputName>"
      PRINT "Example: Span A: info.dat spanfile"
      PRINT "   Note: Span will automatically assign the extension"
      PRINT "         .s01, .s02, etc. to the output file name."
      END
    END SUB       
    '******
    and to unSPAN:
    Code:
    '*****
    'UNSPAN.BAS
    '  
    $STRING 32  ' 32750 bytes
    $COMPILE EXE
    $INCLUDE "PB32.INC"  ' use PB32 library
    
    IF ArgC(COMMAND$) < 2 THEN
      CALL Usage
    END IF
    tDrive$ = ArgV$(1, COMMAND$)
    IF LEN(tDrive$)<2 THEN tDrive$ = tDrive$ + ":"
    outFile$ = ArgV$(2, COMMAND$)
    
    ON ERROR GOTO ErrorHandler
    inFile$ = DIR$(tDrive$ + "*.s01")
    IF LEN(inFile$) < 1 THEN
      PRINT
      PRINT " No Span File to UnSpan!"
      END
    END IF
    
    inFile$ = LEFT$(inFile$, INSTR(inFile$,".")-1)
    tFile$ = tDrive$ + inFile$ + ".s01"
    ncount% = 1
    
    ihandle? = FREEFILE
    OPEN tFile$ FOR BINARY AS ihandle?
    inLen& = LOF(ihandle?)
    inbytes& = MIN(32256, inLen&)
    
    ohandle? = FREEFILE
    OPEN outFile$ FOR BINARY AS ohandle?
    DO
      GET$ ihandle?,inbytes&, buffer$
      DECR inLen&, inbytes&
      PUT$ ohandle?, buffer$
      inbytes& = MIN(32256, inLen&)
      IF inbytes& < 1 THEN
        CLOSE # ihandle?  ' first close file on disk
    ' Prompt to insert next disk
        CLS
        PRINT " Current File Read!"
        PRINT
        PRINT " Insert Next Disk"
        PRINT
        PRINT " Press Q to Finish, or"
        PRINT " press any key to continue."
        WHILE INSTAT
          i$ = inkey$
        WEND  ' empty keyboard buffer
        WHILE NOT INSTAT : WEND
        i$ = UCASE$(inkey$)
        IF i$ = "Q" THEN EXIT LOOP
        CLS
    
        INCR ncount%, 1
        temp$ = LTRIM$(STR$(ncount%))
        IF LEN(temp$) < 2 THEN temp$ = "0" + temp$
        tFile$ = tDrive$ + inFile$ + ".s" + temp$
        DO
          IF LEN(DIR$(tFile$)) THEN EXIT LOOP
          PRINT
          PRINT
          PRINT "Wrong Disk!  Input disk containing " + tFile$
          PRINT
          PRINT " Press Q to Finish, or"
          PRINT " press any key to continue."
          WHILE INSTAT
            i$ = inkey$
          WEND  ' empty keyboard buffer
          WHILE NOT INSTAT : WEND
          i$ = UCASE$(inkey$)
          IF i$ = "Q" THEN CLOSE : END
          CLS
        LOOP
        OPEN tFile$ FOR BINARY AS ihandle?
        inLen& = LOF(ihandle?)
        inbytes& = MIN(32256, inLen&)
      END IF
    
    LOOP
    
    PRINT "Finished!"
    CLOSE
    END
    
    ErrorHandler:
      CLOSE
      PRINT "Drive Not Ready!"
      END
    
    SUB Usage
      PRINT
      PRINT "  Usage: UnSpan <drive> <outputName>"
      PRINT "Example: UnSpan A: spanfile.exe"
      PRINT "   Note: UnSpan will automatically look for the first"
      PRINT "         file ending .s01 to determine the input file name."
      END
    END SUB
    '*****
    Regards,

    ------------------
    [email protected]
    :) IRC :)

    Comment


    • #3
      ftp://ftp.pkware.com/PK250DOS.EXE
      Code:
      Backup with spanning using PkZip
      Syntax: BAKUP C:\FOLDER
      BAKUP.BAT 
      pkzip -rP -&fv a:myfiles.zip %1\*.*
      .....................................
      REST.BAT
      cd\
      pkunzip -d a:myfiles.zip


      ------------------
      How long is an idea? Write it down.

      Comment


      • #4
        If you would like to back up you files within the program and without shelling out to DOS, you might consider this code

        function space.a&(drive) ' 0 = default, 1 = "A" 2 = "B" etc.
        reg 1,&h3600
        reg 4,drive
        call interrupt &h21
        t1 = reg(1) : if t1 < 0 then t1 = t1 + 65536
        t2 = reg(2) : if t2 < 0 then t1 = t2 + 65536
        t3 = reg(3) : if t3 < 0 then t3 = t3 + 65536
        space.a& = t1 * t2 * t3
        end function

        This function will return the amount of available space on the target drive. You can then write your code to make the determination on how much data you can write to the drive.

        This function can also be used to determine if a diskette is in the drive without crashing the program. If the AX (reg(1)) register is &hFFFF (decimal -1) you probably don't have a diskette in the drive.


        ------------------
        There are no atheists in a fox hole or the morning of a math test.
        If my flag offends you, I'll help you pack.

        Comment


        • #5
          Although DOS limitations may prevent it in this case-- you might note that multiplying three integers may produce a number much larger than will fit into a LONG. I'd suggest redefining space.a& as a QUAD to avoid the potential for problems.

          You might also want to avoid using periods in function names to avoid future compatibility issues, as it makes your function look like a reference to a user-defined type.

          ------------------
          Tom Hanlin
          PowerBASIC Staff

          Comment


          • #6
            Another note: instead of testing for negative values, just use BITS??() to convert the signed INTEGER value to an unsigned WORD before the calculation.

            Here is the code I use:

            Code:
            function FreeSpace&&(Drive%) local public
                    reg 4, Drive%
                    reg 1, &H3600
                    call interrupt &H21
                    function = bits??(reg(2)) * bits??(reg(3)) * bits??(reg(1))
            end function



            ------------------
            Lance
            PowerBASIC Support
            mailto:[email protected][email protected]</A>
            Lance
            mailto:[email protected]

            Comment

            Working...
            X