Store a reference to a file
From REALbasicWiki
| This article is a stub. You can help the REALbasicWiki community by expanding it. |
| Overall article skill | ✭ |
There are many cases where you need to store a reference to a file, i.e. some information which allow to retrieve the original FolderItem later.
Probably inspired from the alias system of Mac OS, REALbasic implements GetSaveInfo and GetFolderItem to achieve this goal. Most notably, the save info allows to retrieve a file even if it has been moved or renamed.
[edit] Store the reference
[edit] Absolute reference
You get the save info simply by:
dim mySaveInfo as string = f.GetSaveInfo( nil )
We use nil as the base folder because we want an absolute reference to the file. Now you can store the string in the file you want.
NOTE: the save info string is not human-readable and may contain non-printable characters. In some cases, you may need to encode it, e.g. with EncodeBase64(), before storing it.
[edit] Retrieve the file
dim f as FolderItem = GetFolderItem(mySaveInfo)
//Update save info if necessary
if f<>nil and StrComp(mySaveInfo, f.GetSaveInfo(nil), 0)<>0 then
// <--- Update the new save info in your storage file
end if
will retrieve the file, or return nil if it fails.
NOTE: the file is retrieved even if it has been moved or renamed, but the magic behind this may have some limitations. That is why you should update the save info whenever it has changed.
