How are Relative vs Absolute paths marked?

While looking at the Media section of the Gramps Data Model diagram, there doesn’t seem to anything to show how the Path is marked as using the Relative Media Path instead of the Absolute path.

Is that missing?

The Sphinx documentation has path manipulation options.

gramps.gen.utils.file. media_path (db )[source]

Given a database, return the mediapath to use as basedir for media

gramps.gen.utils.file. media_path_full (db, filename )[source]

Given a database and a filename of a media, return the media filename is full form, eg ‘graves/tomb.png’ becomes ‘/home/me/genea/graves/tomb.png

gramps.gen.utils.file. relative_path (original, base )[source]

Calculate the relative path from base to original, with base a directory, and original an absolute path On problems, original is returned unchanged

The we use media_path_full utility function to return an absolute path before opening the file.

1 Like

Thanks for the direction.

It looks like GEDCOM7 file paths works in a similar manner. Except that they store a default base directory path in the Header and explicitly use the RELA tag again to state that the object’s path (which, unlike Absolute paths, does not start with a slash directory separator) is relative to the same base directory.

2 VERS 7.0
2 RELA /Users/username/Documents/Genealogy
0 @M1@ OBJE
1 FILE Photos/Family/reunion2023.jpg
2 RELA /Users/username/Documents/Genealogy
1 FORM jpg
1 TITL Family Reunion 2023

This SuperTool script (a "SuperTool Script" type Note in .gramps XML format) can be pasted into the [**Import Text** add-on gramplet]( Pressing the Import button creates the Note.

Then switch categories to Media and use the SuperTool addon tool to import the the script from the Note (FileLoad from Note). Select some Media object and use the Execute button to show which which use Absolute or Relative paths.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE database PUBLIC "-//Gramps//DTD Gramps XML 1.7.1//EN"
<database xmlns="">
    <created date="2024-07-05" version="5.2.1"/>
    <note handle="_fa5315d935a39708c614075dc67" change="1720219116" id="N0012" type="SuperTool Script">
      <text>[Gramps SuperTool script file]

Media paths

Determine if selected Media objects have a Relative path or an Absolute one
See Discussion in


from gramps.gen.utils.file import media_path_full, media_path
relative_path = media_path(db)

absolute_path = media_path_full (db, path )
object_path = path
compare_path = "Relative path: " + relative_path
if absolute_path == object_path : compare_path = "Absolute path"


object_path, compare_path