NAME
RestoreIfExists — Replace file with backup, if one can be found.
SYNOPSIS
RestoreIfExists FilePathValue ?Extension?
DESCRIPTION
Return Value
1 Did do a restore.
0 Did not do a restore.
Arguments
FilePathValueFile path of original, without the .bak extension.
ExtensionOptional. Name of the extension the backup version should have. Defaults to bak.
More Info
Checks to see if a backup file for the given file exists. If it does, then this command makes a copy from that, taking away the .bak ending. RestoreIfExists my.txt will look for a file called my.txt.bak, and if it finds one then it will copy from that to my.txt.

Again, note that "IfExists" here refers to the version with the extension (and not the original). So, if you have foo.txt, back it up as foo.txt.bak, and delete the original, then RestoreIfExists foo.txt will create foo.txt. On the other hand, if you have foo.txt and do not back it up (so there is no such file as foo.txt.bak) and then you call RestoreIfExists foo.txt, it will not be an error but rather it will do nothing and return zero.

This command is meant to be paired with BackupIfExists to make for a very primitive, "one version only" backup mechanism to use with applications.


For information regarding exceptions / errors, see here.
EXAMPLES
% String2File "First" test.txt
% BackupIfExists test.txt
Copying test.txt to test.txt.bak
1 file(s) copied.
% String2File "Second" test.txt
% cat test.txt
Second
% RestoreIfExists test.txt
Copying test.txt.bak to test.txt
1 file(s) copied.
% cat test.txt
First
SEE ALSO
BackupIfExists, file
KEYWORDS
file