Page 1 of 1

CopyFile()

Posted: Thu Sep 14, 2017 11:02 pm
by IdeasVacuum
Before Overwriting an existing file, it is good practice to make a copy of it (backup), so a CopyFile() function would be great......

Work-around is to read existing file-write backup file, roughly this:

Code: Select all

Procedure.i PfCopyFile(sFile1.s, sFile2.s)
;#----------------------------------------
Protected iFormat.i

              If ReadFile(1, sFile1)

                     If(Lof(1) > 1)

                            If CreateFile(2, sFile2)

                                   iFormat = ReadStringFormat(1)
                                   
                                   While Eof(1) = 0
                                   
                                           WriteStringN(2, ReadString(1, iFormat), iFormat)
                                   Wend
                                   
                                         CloseFile(2)
                                   ProcedureReturn(#True)
                            EndIf
                     EndIf

                     CloseFile(1)
              Else
                     ProcedureReturn(#False)
              EndIf
EndProcedure