Changing the photos folder in F-Spot
After I moved my stuff to a new hard disk, F-Spot couldn’t find my photos anymore. The path to the photos folder had changed, because I adopted a new user name. If you ever get yourself in this situation, here are some steps to fix the sqlite database.
After you move your photos, set the corresponding F-Spot preference. If you are moving to a new partition or HD, make sure you bring the database too: ~/.gnome2/f-spot/photos.db. Remember, you really should make a backup before you mess with the database! Now, open a copy of the database:
$ sqlite3 photos.db
SQLite version 3.5.6
Enter “.help” for instructions
sqlite> select id, uri from photos;
…
716|file:///home/usuario/Photos/2007/12/12/100_0976.jpg
717|file:///home/usuario/Photos/2007/12/12/100_0977.jpg
718|file:///home/usuario/Photos/2007/12/12/100_0978.jpg
719|file:///home/usuario/Photos/2007/12/12/100_0979.jpg
720|file:///home/usuario/Photos/2007/12/12/100_0980.jpg
721|file:///home/usuario/Photos/2007/12/12/100_0981.jpg
722|file:///home/usuario/Photos/2007/12/12/100_0982.jpg
…
sqlite>
You have to see how long is the URI part you want to fix. If you want to change “Photos” for “Fotografias”, you’ll have to change everything from “file://” to “Photos”. In that case, the command would be:
sqlite> update photos set uri = ‘file:///home/usuario/Fotografias’|| substr(uri,28);
sqlite>
The number 28 is the lenght of “file:///home/usuario/Photos”, plus 1 (don’t ask me why). Now, check if you did it right:
sqlite> select id, uri from photos;
…
716|file:///home/usuario/Fotografias/2007/12/12/100_0976.jpg
717|file:///home/usuario/Fotografias/2007/12/12/100_0977.jpg
718|file:///home/usuario/Fotografias/2007/12/12/100_0978.jpg
719|file:///home/usuario/Fotografias/2007/12/12/100_0979.jpg
720|file:///home/usuario/Fotografias/2007/12/12/100_0980.jpg
721|file:///home/usuario/Fotografias/2007/12/12/100_0981.jpg
722|file:///home/usuario/Fotografias/2007/12/12/100_0982.jpg
…
sqlite>
The result (correct or not) is already written to the file. If you did a mistake, you can try to fix it, or start over. Remember to keep a backup… To exit sqlite, the command is:
sqlite> .quit
$
I tested these exact steps, as well as changing only the user name (which is what I needed). I guess it’ll work with spaces and special characters, but I can’t guarantee. If you try it, tell me in the comments!
Thanks: This article was made possible because of Roland Mas, who gave me a link to the original instructions in the F-Spot mailing list. Those instructions didn’t fit exactly my situation (e. g. I had “uri” instead of “directory_path”), so I decided to gather his aditional tips in this article.
Other Languages:
Related posts:
Full text feed

![[digg]](http://digg.com/img/badges/16x16-digg-guy.gif)
![[delicious]](http://images.del.icio.us/static/img/delicious.med.gif)
March 21st, 2008 pm31 17:54
can u please stick this on a wiki someplace or get the f-spot to put it on their docs web page because its a very common issue.
March 21st, 2008 pm31 18:23
I thought about that, but then I agreed it’s not a good practice to have users editing the database by hand. I believe this information belongs to an addin (plugin, etc.). I’m not a hacker, but I really hope someone scratches that itch.
March 22nd, 2008 am31 03:34
I’ve had to do this before, not because of a username change, but just out of convenience.. I wrote up a little guide that I haven’t yet “published”.. here it is..
BACKUP ~/.gnome2/f-spot/photos.db
Run the command:
sqlite3 ~/.gnome2/f-spot/photos.db .dump > f-spot.dump
Using whatever method, e.g. the find/replace feature in a text editor, change the information and settings you want to change in the f-spot.dump file.
Delete ~/.gnome2/f-spot/photos.db
Run the command:
sqlite3 ~/.gnome2/f-spot/photos.db
March 22nd, 2008 pm31 15:01
That’s interesting! There is more data to mess with, but the interface will be more familiar.
I guess the last command was supposed to be
sqlite3 ~/.gnome2/f-spot/photos.db < f-spot.dump?March 22nd, 2008 pm31 16:18
Actually there is an extension for just this case….
http://f-spot.org/Extensions
Check the ChangePath extension
March 22nd, 2008 pm31 16:19
Actually there is an extension for this…
http://f-spot.org/Extensions
Check the ChangePath extension
March 22nd, 2008 pm31 22:14
Yes, it is. Somehow I didn’t copy the whole thing :S.
March 24th, 2008 pm31 14:44
I’ve done similar operation with Banshee some time ago. Since I know the sql not so much I have done it with support of irb or python (I don’t remember). It allowed me to do it in steps:
1. Open the connection
2. Get data and print
3. Get data change it (i.e. in local memory) and print
4. Get data change it and write to the file
5. Flush, close the connection etc.
If it was a real application I would learn correct commands of the SQL. However since it was run once it allow me to ommit ‘28′.
PS.
Is it not be better style if it was:
update photos set uri = ‘file:///home/usuario/Fotografias’|| substr(uri,length(’file:///home/usuario/Photos’));
March 25th, 2008 am31 04:51
> The result (correct or not) is already written to the file. If you did a mistake, you can try to fix it, or start over. Remember to keep a backup…
You could also start a transaction before modifying the database. When you are satisfied with the changes, you can commit the transaction, but if you made a mistake, you can rollback and the database is still intact.
sqlite> begin;
sqlite> some sql statement here
sqlite> commit; (or rollback;)
March 25th, 2008 am31 05:39
> You could also start a transaction before modifying the database.
I know. I know ;). But to program it in some kind of scripting language is by far more transparent and UF for me. As I said in real-live application I would use SQL.
March 25th, 2008 pm31 23:34
Bengt: thanks for the information, an extension is much better than messing with SQL. I’m not sure the 0.4.1 version works with F-Spot 0.4.2, though. Anyway, I’m sorry for my anti-spam bad behavior…
June 17th, 2008 pm30 22:43
Hi, thanks for the tips.
I think updating the path would be easuer using replace syntax - saves you from counting characters
update photos set uri = replace(uri,’/home/olduser/’,'/home/newuser/’);
June 17th, 2008 pm30 23:04
Vitaliy: thanks for the tip, your way is much more user-proof than mine
June 26th, 2008 am30 08:12
Olá, Leonardo!
Sou aluna de Jornalismo, do Brasil.
Estou fazendo uma matéria para o nosso jornal-laboratório da faculdade sobre o novo acordo ortográfico e estava procurando informações a respeito quando achei esse texto seu…
Precisava de alguém de Portugal para retratar a opinião na minha matéria. Você poderia me ajudar?
Se possível, responda às questões abaixo e me envie a resposta o quanto antes (pois estou fechando a matéria já) acompanhado de uma foto sua.
- Como você vê essa mudança na gramática portuguesa? Favor ou contra/ E por que?
- Qual é o posicionamento dos portugueses diante desta questão?
Só confirmando.. preciso do seu nome completo, função que exerce no dia-a-dia e onde mora.
Obrigada.
Angélica Neri - Brasil.
June 27th, 2008 am30 06:34
Angélica, this article is not related to the Orthographic Agreement. Would you please make theses questions again in the comments section of an article in Portuguese, and related to the Agreement?