Create a backupfile RRS feed

  • General discussion

  • I need often to save a backup file of the original to keep a copy of it. Windows is using a “-copie(1)” extend. So I was writing a sample. Probably there are already some other examples I didn’t found (litdev ??). I used a function to document some of the the steps, you can change infonumber=1, and  the linenumbers are in the answers. I was hardcoding some filenames and did not include a test to verify if the file exist,  such as the ldevfile(exist) command –as- the topic is to verify if the program is running correctly and the filenames are defined somewhere else in the program. BJC721. File Egide.gpx will be replaced with Egide-copie(1).gpx,Egide-copie(2).gpx...


    Infonumber="0" 'To be set to 1 to see more information args="" TextWindow.left=100 ' xxxxxxxxxxxxxxx uncomment the file you want to verify 'BackupFile="d:\data\small-Basic\gpxcleaner-800\Egide.gpx" 'BackupFile="d:\data\small-Basic\gpxcleaner-800\Egide-copie(3).gpx" 'BackupFile="out-123-copie(23).gpx" BackupFile="Egide-copie(5).gpx" 'BackupFile="out-123.gpx" 'BackupFile="" LDCall.Function3("InfoFunc","0","11-BackupFile= "+BackupFile,"Yellow") Bcf=text.getlength(BackUpFile) 'backupFilelength For ctrb=Bcf To Bcf-15 Step -1 'Ctrb backwards counter in backupfile Bcfchar=Text.GetSubText(backupfile,ctrb,1) If Bcfchar="." Then dotpos=ctrb 'position of the dotpoint ElseIf Bcfchar=")" Then parclosepos=ctrb 'position of close parenthesis ElseIf Bcfchar="(" Then paropenpos=ctrb 'position of open parenthesis ElseIf Bcfchar="-" Then minpos=ctrb ''position of open parenthesis minus sign EndIf EndFor LDCall.Function3("InfoFunc","1","26-bcf= "+bcf+" dotpos= "+ dotpos + " parclosepos= "+parclosepos +" paropenpos= "+ paropenpos+" minpos= "+ minpos,"White") 'Note : 24 is the linenumber for debugging fileextend= Text.GetSubTextToEnd(backupfile,dotpos+1) LDCall.Function2("InfoFunc","1","29-fileextend = "+ fileextend) If text.converttolowercase(Fileextend) <> "gpx" Then 'Test if extend gpx is present LDCall.Function2("InfoFunc","1","32-NO File extend or Fileextend is not Gpx !") ElseIf minpos<paropenpos and paropenpos<parclosepos Then 'test if -copie(nr) FileCp=Text.GetSubText(backupfile,minpos,paropenpos-minpos) LDCall.Function2("InfoFunc","1","36-FileCp= "+FileCp) Filenr=Text.GetSubText(backupfile,paropenpos+1,parclosepos-paropenpos-1) LDCall.Function2("InfoFunc","1","38-Filenr= "+Filenr) If FileCp="-copie" and text.getlength(filenr+0)=text.getlength(filenr) Then 'Test if nr is a number and not text newbackupfile=text.getsubtext(backupfile,1,paropenpos)+(filenr+1)+text.getsubtexttoend(backupfile,parclosepos) LDCall.Function2("InfoFunc","1","41-newbackupfile = "+newbackupfile) EndIf Else newbackupfile=text.getsubtext(backupfile,1,dotpos-1) +"-copie("+1+")"+text.getsubtexttoend(backupfile,dotpos) LDCall.Function2("InfoFunc","1","46-newbackupfile = "+newbackupfile) EndIf LDCall.Function3("InfoFunc","0","49-newbackupfile = "+newbackupfile,"Red") 'xxxxxxxxxxxxxxxxxx Subroutines xxxxxxxxxxxxxxxxxxxx Sub InfoFunc 'TextWindow.WriteLine("Infonumber= "+Infonumber+" args1 = "+args[1]) If Infonumber = 0 and args[1] = 0 Then TextWindow.ForegroundColor=(args[3]) TextWindow.WriteLine(args[2]) EndIf if Infonumber = 1 and args[1] <= 1 then TextWindow.ForegroundColor=(args[3]) TextWindow.WriteLine(args[2]) EndIf EndSub

    Short remark : it's not completely Windows compliant ... windows is including a lot of spaces before and behind copie and the minus sign- such as "Egide - Copie (5).Gpx"   and the first copy will be "Egide - Copie.Gpx". It seems the word copie is also language dependent.  As these spaces are not accepted with some GPS's, etc  I preferred not to follow the real windows-standards. So the first copy will be 

     "Egide-Copie(1).Gpx" and the other ones  "Egide-Copie(2).Gpx", etc. 

    • Edited by Eddy Abts Monday, May 11, 2020 4:29 PM
    • Changed type Nonki Takahashi Wednesday, June 17, 2020 1:19 PM no questions
    Monday, May 11, 2020 12:50 PM