TABLE OF CONTENTS


::pwtk::file_backup

SYNOPSIS

proc ::pwtk::file_backup {filename {postfix bck}} {

PURPOSE

Backup the file or directory if it exists. Specifying a non-existent file (directory) is not considered an error.

Specifying a non-existent file is not considered an error.

ARGUMENTS

RETURN VALUE

The name of the backup file (or empty string if the filename does not exist).

SOURCE

    if { [file exists $filename] } {
        set i ""        
        while { [file exists ${filename}.${postfix}$i] } {
            if { $i eq "" } { set i 0 }
            incr i
        }
        file copy -- $filename $filename.${postfix}$i
        return $filename.${postfix}$i
    }
    return {}
}