View Single Post
Old 07-13-2010, 03:09 PM   #1
tobidope
Junior Member
tobidope began at the beginning.
 
Posts: 3
Karma: 10
Join Date: Jul 2010
Device: Kindle 2
Calibre leaving behind garbage in the filesystem?

Hello

after looking through my Calibre folder I noticed there are some folders which don't have a corresponding author. It seems that after reorganizing my library old files are left behind leading to duplicated files. Can anyone else confirm this? I cleaned my Calibre folder with the following python script
Code:
# -*- coding: utf8 -*-
import os
import shutil
import sqlite3

BASE_PATH = r'C:\Users\tobias\Documents\My Dropbox\Public\Calibre Bibliothek'
DB = 'metadata.db'
CALIBRE2OPDS_FOLDER = '_catalog'

con = sqlite3.connect(os.path.join(BASE_PATH, DB))
db_folders = set(n[0].split('/')[0] for n in con.execute('select path from books').fetchall())
con.close()
file_folders = set(d for d in os.listdir(BASE_PATH)
                   if os.path.isdir(os.path.join(BASE_PATH, d)) and
                   d != CALIBRE2OPDS_FOLDER)

for f in file_folders - db_folders:
    print("Deleting unused directory {0}".format(f))
    shutil.rmtree(os.path.join(BASE_PATH, f))
I haven't opened a bug till now. Still wondering if I'm doing something wrong.

Regards
Tobias
tobidope is offline   Reply With Quote