Additionally test the ISFILE function after update PB 9.03. Must be tested on PBCC 5.03.
WIN32API.INC file must be included to solve %SUBDIR equate.
Code:
'¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ ' Simple backup procedure with incremental filenames in a subfolder. ' - Preserve old backup copies. ' - Retaing original date and time ' - Maintain original file extension (more practical if you have to edit) ' - Original file remains unaltered ' Use new PBWin 9 functions. ' Tested with 9.03 on Windows Vista ' i.e. "C:/Source/Routine.bas" becomes "C:/Source/BkFolder/Routine_001.bas" '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ Sub MakeBackupN(ByVal fName As String) 'complete full drive/path/file name Local n As Long Local BkFile,fTemp As String 'create subfolder if not exist BkFile = PathScan$(Path, fName) + "BkFolder" '<--- change name if wish If Len(Dir$(BkFile, %SUBDIR)) = 0 Then MkDir BkFile 'create new if needed 'get the NAME and the EXTN parts combined. fTemp = BkFile + "\" + PathScan$(Namex, fName) 'add to NAME portion of the path/file name with a non existing 'numerical suffix, retaining current extension Do Incr n If n > 990 Then MsgBox "BkFile limit reached ..." 'some action to alert BkFile = fTemp Replace "." With "_" + Format$(n, "000") + "." In BkFile Loop Until IsFile(BkFile) = %FALSE 'use first free number FileCopy fName, BkFile 'copy file to backup End Sub '¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
Leave a comment: