1 | Did do a restore. |
0 | Did not do a restore. |
FilePathValue | File path of original, without the .bak extension. |
Extension | Optional. Name of the extension the backup version should have. Defaults to bak. |
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.
% 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