Function File Operations Class

NameBackupTarget

Rename a file and keep a backup of the target file if the target file already exists. Backup file has same name as target file except that last character is changed to a hyphen ("-").

Signature (Visual Basic / VBA)

Public Function NameBackupTarget( _
      ByVal vFromFileName As Variant _
    , ByVal vToFileName As Variant _
    ) As Boolean

Code Example

    StringToFile("First.", "Debug.Out") = True
    NameBackupTarget("Debug.Out", "Debug.1") = True
    StringToFile("Second.", "Debug.Out") = True
    ' Next call renames Debug.1 to Debug.-
    ' then renames Debug.Out to Debug.1
    NameBackupTarget("Debug.Out", "Debug.1") = True
    FileToString("Debug.1") = "Second."
    FileToString("Debug.-") = "First."

Parameters

Parameter Description
vFromFileName Current name of the file; the name that is to be changed. Function does nothing and returns False if vFromFileName is Null or cannot be fixed-up to a String.
vToFileName New name for the file; the name that it will be changed to. Function does nothing and returns False if vToFileName is Null or cannot be fixed-up to a String. If the last character of vToFileName is already a hyphen, then no backup is kept.

Notes & Version History

v1.2 BugFix Changed the argument types from String to Variant to be more consistent with the other functions in this Class.
v1.2 Change Changed to use the Visual Basic FileCopy statement so that vFromFileName and vToFileName no longer have to reside on the same drive.