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
- filename -- name of a file or directory
- postfix -- (optional, default = bck) postfix for the backup copy, i.e., the backup is named '$filename.${postfix}$i', where $i is an empty string or an integer (chosen such that '$filename.${postfix}$i' does not pre-exists)
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 {} }