I usually store files in a database as path reference. I use the NativePath value of a FolderItem object.
But I would rather refer to a relative path. My database is a project file. In my project, I point to media resources needed in my project.
But, as I backup my project, I usually copy (or move) the project along with the resource files to a new (remote) location. As long I keep my project’s folder structure intact, everything should be working fine.
Since I store files with the NativePath value, they keep pointing to a place where the resources no longer reside.
Is there already a way to get a FolderItem that is relative to another one?
Thanks…
But getFolderItem(“”) will return the Executable’s parent-folder, right?
I don’t want that. When I open a project (the SQLite Database), the resource files will need to be relative to that project file, not the application.
Of course, it needs to go both ways: getting a relative path and setting a relative:
// projectFile is a FolderItem property in some Class
// myVideoFile is a FolderItem of a resource video file
' this should return "../VideoFiles/myVideo.mxf"
dim myResourcePath as string = projectFile.RelativePath( myVideoFile )
' this should return the actual FolderItem of the relative path
dim myResourceFile as FolderItem = projectFile.RelativeItem( "../VideoFiles/myVideo.mxf" )
I was just wondering if this already exists in Xojo. I just can’t find it. Otherwise, I would make my own.
If you care to try and understand what GetSaveInfo is all about, that should fit perfectly what you need. And dump these outdated paths. That will help a lot.
So if what is stored is VideoFiles/myVideo.mxf
and the path to the project file is known
then the file would be
.child(“VideoFiles”).child(“myVideo.mxf”)
The delimiter here is a slash, but could just as easily be any character… the trick is just to split the relative folders that were stored and turn them into successive .child references?