Jeremiah Rose
Jeremiah Rose

Reputation: 4132

How to obtain a "permalink" to files on a personal hard-drive

Background: I write a lot of personal notes on all sorts of topics for work, life and hobbies. In my notes I often want to refer to personal files on my harddrive. I can do this by referencing the file's location using a URI like this: file:///Users/geoffrey/Pictures/Duckroll.png. However, if this file is moved or renamed, the link becomes broken.

On the world wide web there is the concept of a "permalink", which is a link to a resource that comes with a strong assurance that the link will continue to work even if the resource is moved or renamed.

For example, the following permalink from Wikipedia is guaranteed to continue working even if the "Rickrolling" article happens to be renamed to "Duckrolling", or something else: https://en.wikipedia.org/w/index.php?title=Rickrolling&oldid=1246005002

My question is, how can a permalink be created for files on a personal hard-drive, so that if the file is moved to a different location, or renamed, or deleted and recreated elsewhere, then the link still remains valid?

Upvotes: 0

Views: 60

Answers (1)

bylal
bylal

Reputation: 141

You could use symlinks and update them as you rename files but it goes against the automatic updates of the file's location.

Therefore I would suggest to:

  1. Generate unique uuids for your files

generate unique uuids for all your (relevant) files.

  1. In one folder create all your symlink

create symlinks (working as permalink) pointing to them.

  1. Monitor rename/move (eventually deletion)

Lastly you could use iNotify or FileSystemWatcher to detect when a file is moved or renamed (or deleted) and write a script that automatically updates the symlink to the new file's location (eventually delete the symlink if the file is deleted).

Upvotes: 0

Related Questions