'===========================================================================
' Subject: FILE COPIER V0.1                   Date: 04-23-99 (18:32)       
'  Author: Yousuf Philips                     Code: QB, QBasic, PDS        
'  Origin: philipz@emirates.net.ae          Packet: MISC.ABC
'===========================================================================
''''''''''''''''''''''''''''''''''''''
' Program    : File Copier           '
' Name       : FILECOPY Version 0.1  '
' Programmer : Yousuf Philips        '
' Company    : Y P I                 '
' Updated On : 1st of Feb. 1998      '
' Email - [philipz85@hotmail.com]    '
' [http://members.xoom.com/Philipz/] '
''''''''''''''''''''''''''''''''''''''

'/*               Do not edit this file if you distribute it.              */'
'/*  (c) Copyrighted by YPI in 1999 | All Rights Reserved | Public Domain  */'

'/* This program has been created by YPI (Basic Programming Incorporation) */'
'/* as a utility to copy files in QBASIC from one location to another.     */'
'/*                                                                        */'
'/* If you use any of this code in your program then you must credit YPI,  */'
'/* it would be appreciated if you sent us a copy of your program also.    */'
'/* Please send your comments and suggestions to <philipz85@hotmail.com>   */'

DECLARE FUNCTION CopyFile% (FileToCopy$, FileToCopyTo$, CopyOver%)
'/* FileToCopy$ - The file with the data you want to copy from             */'
'/* FileToCopyTo$ - The file you want to copy the data to                  */'
'/* CopyOver% - Possible Values                                            */'
'/*             0 - Program will prompt you to overwrite file              */'
'/*             Not 0 - Program will not prompt you to overwrite file      */'
'/* CopyFile% - Possible Values after function has completed               */'
'/*             0 - An error occured while trying to copy the file         */'
'/*             1 - File was successfully copied                           */'

CLS
PRINT
PRINT " QBASIC File Copier - FILECOPY ver 0.1"
PRINT " (c) YPI (BASIC Programming Incorporation) 1999"
PRINT " Copying c:\autoexec.bat to c:\auto.bat"
PRINT " Continue With Demostration <Y/N>"
DO
   KeyPressed$ = INKEY$
   KeyPressed$ = UCASE$(KeyPressed$)
LOOP UNTIL KeyPressed$ = "Y" OR KeyPressed$ = "N"
IF KeyPressed$ = "Y" THEN
   Runz = CopyFile("c:\autoexec.bat", "c:\auto.bat", 0)
   IF Runz = 1 THEN
      PRINT " File Transfer Completed"
   ELSE
      PRINT " File Transfer Not Done Due To Error"
   END IF
ELSE
   PRINT " File Transfer Not Done"
END IF
PRINT
PRINT " Program is Public Domain, All Rights Reserved"
PRINT " Send suggestions and comments to philipz85@hotmail.com"
PRINT " Visit the YPI Website at http://members.xoom.com/Philipz/"

DEFINT A-Z
FUNCTION CopyFile (FileToCopy$, FileToCopyTo$, CopyOver)

'/* If the source and destination files are the same then the program ends */'
IF FileToCopy$ = FileToCopyTo$ THEN
   PRINT " Can't Copy File Onto Itself"
   CopyFile = 0
   EXIT FUNCTION
END IF

'/* Open the source and destination files                                  */'
OPEN FileToCopy$ FOR BINARY AS #254
OPEN FileToCopyTo$ FOR BINARY AS #255

SourceFileLength = LOF(254): DestinationFileLength = LOF(255)
'/* If the source file is empty then it is deleted and the same for the    */'
'/* destination file                                                       */'
IF SourceFileLength = 0 THEN
   PRINT " Source File Is Empty"
   CLOSE
   KILL FileToCopy$
   IF DestinationFileLength = 0 THEN
      KILL FileToCopyTo$
   END IF
   CopyFile = 0
   EXIT FUNCTION
END IF

'/* Prompts user if the destination file is not empty                      */'
IF DestinationFileLength <> 0 THEN
   '/* If the variable CopyOver is equal to 0 then the user is prompted if */'
   '/* he/she would like to overwrite the file                             */'
   IF CopyOver = 0 THEN
      PRINT " The Destination File Is Not Empty"
      PRINT " Should It Be Copied Over <Y/N>"
      DO
         YN$ = INPUT$(1)
      LOOP UNTIL UCASE$(YN$) = "Y" OR UCASE$(YN$) = "N"
      IF UCASE$(YN$) = "N" THEN
         CopyFile = 0
         EXIT FUNCTION
      END IF
   END IF
   CLOSE #255
   KILL FileToCopyTo$
   OPEN FileToCopyTo$ FOR BINARY AS #255
END IF

BytesToExtract = 1000: NoOfLoops = SourceFileLength \ BytesToExtract
ExtractFromFile$ = SPACE$(BytesToExtract)

'/* Moves BytesToExtract bytes from source to destination everly loop      */'
FOR Loops = 1 TO NoOfLoops
   GET #254, , ExtractFromFile$
   PUT #255, , ExtractFromFile$
NEXT Loops

'/* Moves any remaining bytes from source to destination                   */'
BytesLeft = SourceFileLength - (NoOfLoops * BytesToExtract)
ExtractFromFile$ = SPACE$(BytesLeft)
GET #254, , ExtractFromFile$
PUT #255, , ExtractFromFile$
CLOSE

'/* Routines for setting the date and time to a file must be used if need  */'
CopyFile = 1

END FUNCTION
