TIP: Click on subject to list as thread! ANSI
echo: power_bas
to: KEN UZZELL
from: THOMAS GOHEL
date: 1996-09-09 00:00:00
subject: Re: File Copy

In article "File Copy" (on 02.09.96), Ken Uzzell@3:711/453 says:
Hello Ken !!
> In one application I am developing, I have to copy binary files from one
> directory to another as part of its function.
>
> In my older MS Basic, I used a provided library to do this, thus I never
> developed the programming expertise to write code to copy binary files.
Here are two sources for PowerBASIC. The first source is very simple, the
second source supports the original time- and datestamps for the
destination file, too:
OPEN "C:\COMMAND.COM" FOR BINARY AS #1
OPEN "C:\COMMAND.BAK" FOR BINARY AS #2
DO WHILE NOT EOF(1)
    GET$ #1, 32000, Copy$
    PUT$ #2, Copy$
LOOP
CLOSE #1
CLOSE #2
and the second source:
'*************************************************************************
'
'   FileCopy in PowerBASIC 3.1/3.2
'
'   entwickelt von / developed by   :  Thomas Gohel
'                           Fido    :  Thomas Gohel@2:2410/301.12
'                           InterNet:  author@pbsound.snafu.de
'                           Homepage:  http://www.snafu.de/~pbsound/
'
'**************************************************************************
$COMPILE EXE
DECLARE FUNCTION GetStrLoc (BYVAL INTEGER) AS INTEGER
DECLARE FUNCTION FileCopy%(BYVAL Source$, BYVAL Destination$)
SHARED FileCopyError%
PRINT
PRINT
PRINT "FileCopy mit/with PowerBASIC 3.1/3.2";TAB(50);"(c) 1994/96 von/by 
Thomas Gohel";
PRINT
DosIoError% = FileCopy%("F:\TEST\TEST.TXT", "F:\TEST\TEST.BAK")
IF DosIoError% > 0 THEN
    PRINT
    PRINT "Error detected: ";DosIoError%; "(";
    SELECT CASE DosIoError%
        CASE  1
            PRINT "filesharing software not found/function number invalid";
        CASE  2
            PRINT "file not found";
        CASE  3
            PRINT "path not found";
        CASE  4
            PRINT "too many open files (no handles available)";
        CASE  5
            PRINT "access denied";
        CASE 12
            PRINT "access code invalid";
    END SELECT
    PRINT ")"
ELSE
    PRINT
    PRINT "Ok"
END IF
END
FUNCTION FileCopy%(BYVAL Source$, BYVAL Destination$) public
        LOCAL SourceHandle%, DestinationHandle%
        LOCAL FileDate%, FileTime%
        LOCAL BufferLenght%
        LOCATE , 3: PRINT "Kopiere/Copying: ";Source$
        LOCATE , 3: PRINT "        nach/to: ";Destination$
        '*** Variablen Init ***
        Source$        = Source$      + CHR$(0)
        Destination$   = Destination$ + CHR$(0)
        BufferLenght%  = 32000
        Copy$          = STRING$(BufferLenght%, 0)
        '*** Source-Datei ”ffnen / open sourcefile ***
        ! push ds
        ! les  di, Source$               ; Handle von Source$ holen
        ! push di                        ; auf Stack
        ! call GetStrLoc                 ; Adresse holen
        ! mov  ds, dx                    ; DX:AX auf DS:DX umkopieren
        ! mov  dx, ax                    ;
        ! mov  ax, &h3d90
        ! int  &h21
        ! pop  ds
        ! jnc  SourceFileOpenOk
        ! mov  FUNCTION, ax
        ! jmp  FileCopyExit
        SourceFileOpenOk:
        ! mov  SourceHandle%, ax
        '*** Destination-Datei ”ffnen / open destination file ***
        ! push ds
        ! les  di, Destination$          ; Handle von Destination$ holen
        ! push di                        ; auf Stack
        ! call GetStrLoc                 ; Adresse holen
        ! mov  ds, dx                    ; DX:AX auf DS:DX umkopieren
        ! mov  dx, ax                    ;
        ! mov  ax, &h3c00
        ! mov  cx, &h0
        ! int  &h21
        ! pop  ds
        ! mov  DestinationHandle%, ax
        ! jnc  DestinationFileOpenOk
        ! mov  FUNCTION, ax
        ! jmp  FileCopyExit
        DestinationFileOpenOk:
        '*** Source-Datei einlesen / read sourcefile ***
        DO WHILE BufferLenght% = 32000
            ! push ds
            ! les  di, Copy$                 ; Handle von Copy$ holen
            ! push di                        ; auf Stack
            ! call GetStrLoc                 ; Adresse holen
            ! mov  ds, dx                    ; DX:AX auf DS:DX umkopieren
            ! mov  dx, ax                    ;
            ! mov  ax, &h3F00
            ! mov  bx, SourceHandle%
            ! mov  cx, BufferLenght%
            ! int  &h21
            ! pop  ds
            ! mov  BufferLenght%, ax
            ! jnc  ReadOk
            ! mov  FUNCTION, ax
            ! jmp  FileCopyExit
            ReadOk:
            '*** Destination-Datei schreiben / write destination file ***
            ! push ds
            ! les  di, Copy$                 ; Handle von Copy$ holen
            ! push di                        ; auf Stack
            ! call GetStrLoc                 ; Adresse holen
            ! mov  ds, dx                    ; DX:AX auf DS:DX umkopieren
            ! mov  dx, ax                    ;
            ! mov  ax, &h4000
            ! mov  bx, DestinationHandle%
            ! mov  cx, BufferLenght%
            ! int  &h21
            ! pop  ds
            ! mov  BufferLenght%, ax
            ! jnc  WriteOk
            ! mov  FUNCTION, ax
            ! jmp  FileCopyExit
            WriteOk:
        LOOP
        '*** Quelle-Datei Datum lesen / read time/date ***
        ! mov  ax, &h5700
        ! mov  bx, SourceHandle%
        ! int  &h21
        ! mov  FileTime%, cx
        ! mov  FileDate%, dx
        ! jnc  ReadTimeStampOk
        ! mov  FUNCTION, ax
        ! jmp  FileCopyExit
        ReadTimeStampOk:
        '*** Ziel-Datei Datum schreiben / write date/time ***
        ! mov  ax, &h5701
        ! mov  bx, DestinationHandle%
        ! mov  cx, FileTime%
        ! mov  dx, FileDate%
        ! int  &h21
        ! jnc  WriteTimeStampOk
        ! mov  FUNCTION, ax
        ! jmp  FileCopyExit
        WriteTimeStampOk:
        '*** Quelle- & Destination-Datei schlieáen / close files ***
        CloseAllFiles:
        ! mov  ax, &h3E00
        ! mov  bx, SourceHandle%
        ! int  &h21
        ! jnc  SourceFileCloseOk
        ! mov  FUNCTION, ax
        ! jmp  FileCopyExit
        SourceFileCloseOk:
        ! mov  ax, &h3E00
        ! mov  bx, DestinationHandle%
        ! int  &h21
        ! jnc  DestinationFileCloseOk
        ! mov  FUNCTION, ax
        ! jmp  FileCopyExit
        DestinationFileCloseOk:
        ! mov  FUNCTION, 0
        FileCopyExit:
END FUNCTION
> Ken
Regards,
                             ----------------
                                /
                              /  h o m a s
email: author@pbsound.snafu.de
www  : http://www.snafu.de/~pbsound/ (PowerBASIC's Home in Germany)
       PBSOUND - The Sound Blaster Toolkit, PowerBASIC-FAQ, PowerBASIC-
       sources & toolboxes, PowerBASIC on Web, PowerBASIC News and much
       more or less important PowerBASIC stuff.
fax  : +49-30-47300910
--- CrossPoint v3.11 R
---------------
* Origin: -= http://www.snafu.de/~pbsound/ =- (2:2410/301.12)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.