Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Devices

Notices

Reply
 
Thread Tools Search this Thread
Old 05-28-2023, 06:10 PM   #1
tomsem
Grand Sorcerer
tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.
 
Posts: 6,939
Karma: 27060151
Join Date: Apr 2009
Location: USA
Device: iPhone 15PM, Kindle Scribe, iPad mini 6, PocketBook InkPad Color 3
Auto-remove empty .sdr folders from Kindle?

I wonder if it would be possible to have an option to remove the empty .sdr folders when calibre connects to a Kindle. It seems these never get cleaned up, short of Reset.
tomsem is offline   Reply With Quote
Old 05-28-2023, 10:25 PM   #2
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 45,345
Karma: 27182818
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Whenever calibre deletes things itself, it removes empty folders. If you manage files outside of calibre on your kindle then calibre is not going to clean up for you since that would require a full scan of all folders on the device to find empty folders.
kovidgoyal is offline   Reply With Quote
Advert
Old 05-29-2023, 01:39 PM   #3
tomsem
Grand Sorcerer
tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.
 
Posts: 6,939
Karma: 27060151
Join Date: Apr 2009
Location: USA
Device: iPhone 15PM, Kindle Scribe, iPad mini 6, PocketBook InkPad Color 3
Quote:
Originally Posted by kovidgoyal View Post
Whenever calibre deletes things itself, it removes empty folders. If you manage files outside of calibre on your kindle then calibre is not going to clean up for you since that would require a full scan of all folders on the device to find empty folders.
If it just removed the empty .sdr folders from the folder used for wireless downloads (/documents/Downloads/Items01/ on Scribe, might be different on older Kindles), that would be sufficient. Or an optional setting could specify this folder (or a list of them).

And while they can appear elsewhere, that's only when I've side loaded without using calibre and just dropped them in /documents. I don't do it a lot so can just clean those when I notice them.
tomsem is offline   Reply With Quote
Old 05-29-2023, 10:47 PM   #4
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 45,345
Karma: 27182818
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
That might be sufficient for you but it wouldnt be sufficient in general and I dont want to implement things in half baked ways.
kovidgoyal is offline   Reply With Quote
Old 05-30-2023, 05:34 AM   #5
JSWolf
Resident Curmudgeon
JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.
 
JSWolf's Avatar
 
Posts: 79,741
Karma: 145864619
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
Quote:
Originally Posted by tomsem View Post
I wonder if it would be possible to have an option to remove the empty .sdr folders when calibre connects to a Kindle. It seems these never get cleaned up, short of Reset.
What could be done is that could be added to the Kindle driver as an option or a separate plugin to do it.

For example, the Kobo Utilities plugin has an option to remove leftover covers that aren't being used.
JSWolf is offline   Reply With Quote
Advert
Old 05-30-2023, 08:46 AM   #6
theducks
Well trained by Cats
theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.
 
theducks's Avatar
 
Posts: 31,047
Karma: 60358908
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
Look at Quality Check Plugin.
Over a decade ago, Kiwidude added Fix: Cleanup files and folders

Since all plugins are mainly ZIP folders, you can look at / tweak the code as needed
theducks is offline   Reply With Quote
Old 05-30-2023, 11:31 PM   #7
tomsem
Grand Sorcerer
tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.
 
Posts: 6,939
Karma: 27060151
Join Date: Apr 2009
Location: USA
Device: iPhone 15PM, Kindle Scribe, iPad mini 6, PocketBook InkPad Color 3
Quote:
Originally Posted by kovidgoyal View Post
That might be sufficient for you but it wouldnt be sufficient in general and I dont want to implement things in half baked ways.
I trust full folder scan is too 'expensive', and would not want to pay it every time I plug in.

I'm sure I've noticed this before, and just shrugged it off. But for some reason now I cannot not see them every time I go into look at what is on there, and I find it annoying. Chalk it up to retirement, my attention latches on to trivial things and magnifies them.

It is not even just Kindles with this issue. I plugged in my Pocketbook Era, and it has folders devoid of content, with orphaned .sdr folders as well as completely empty folders (this is in the folder managed by calibre).

In the grand scheme of things not a big deal. But it would feel good if there were a Clean Up button somewhere.

Last edited by tomsem; 05-30-2023 at 11:36 PM.
tomsem is offline   Reply With Quote
Old 05-30-2023, 11:50 PM   #8
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 45,345
Karma: 27182818
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Since the kindle just appears as a a disk it should be trivial to write a script that scans and deletes all empty folders on it. In fact here is one:

Code:
import os, sys, contextlib

def rmdir(x):
  with suppress(OSError):
     os.rmdir(x)

for (dirpath, dirnames, filenames) is os.walk(sys.argv[1]):
   for x in dirnames:
      rmdir(os.path.join(dirpath, x))
save it as clean.py and run it as

calibre-debug clean.py E:/

replace E:/ with the drive your kindle is mounted as.
kovidgoyal is offline   Reply With Quote
Old 05-31-2023, 02:03 PM   #9
tomsem
Grand Sorcerer
tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.
 
Posts: 6,939
Karma: 27060151
Join Date: Apr 2009
Location: USA
Device: iPhone 15PM, Kindle Scribe, iPad mini 6, PocketBook InkPad Color 3
Quote:
Originally Posted by kovidgoyal View Post
Since the kindle just appears as a a disk it should be trivial to write a script that scans and deletes all empty folders on it. In fact here is one:

Code:
import os, sys, contextlib

def rmdir(x):
  with suppress(OSError):
     os.rmdir(x)

for (dirpath, dirnames, filenames) is os.walk(sys.argv[1]):
   for x in dirnames:
      rmdir(os.path.join(dirpath, x))
save it as clean.py and run it as

calibre-debug clean.py E:/

replace E:/ with the drive your kindle is mounted as.
It's not Windows, but trivial to modify to take a path. Thanks.
tomsem is offline   Reply With Quote
Old 06-06-2023, 06:00 PM   #10
tomsem
Grand Sorcerer
tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.
 
Posts: 6,939
Karma: 27060151
Join Date: Apr 2009
Location: USA
Device: iPhone 15PM, Kindle Scribe, iPad mini 6, PocketBook InkPad Color 3
Turns out it is not as simple as removing empty folders, though that takes care of most of the lint. (This will also delete empty non-.sdr folders, but that's probably a plus, or at least not likely to cause trouble.)

What is left over are some 'orphaned' (non empty) .sdr folders and temporary files with file extensions of pattern r"tmp\d*_(ASC|PHL)".

I'm working on a standalone version that handles these.
tomsem is offline   Reply With Quote
Old 06-07-2023, 07:00 AM   #11
JSWolf
Resident Curmudgeon
JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.JSWolf ought to be getting tired of karma fortunes by now.
 
JSWolf's Avatar
 
Posts: 79,741
Karma: 145864619
Join Date: Nov 2006
Location: Roslindale, Massachusetts
Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3
Quote:
Originally Posted by tomsem View Post
Turns out it is not as simple as removing empty folders, though that takes care of most of the lint. (This will also delete empty non-.sdr folders, but that's probably a plus, or at least not likely to cause trouble.)

What is left over are some 'orphaned' (non empty) .sdr folders and temporary files with file extensions of pattern r"tmp\d*_(ASC|PHL)".

I'm working on a standalone version that handles these.
A plugin would be nice to have to clean up a Kindle.
JSWolf is offline   Reply With Quote
Old 06-07-2023, 09:12 PM   #12
tomsem
Grand Sorcerer
tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.tomsem ought to be getting tired of karma fortunes by now.
 
Posts: 6,939
Karma: 27060151
Join Date: Apr 2009
Location: USA
Device: iPhone 15PM, Kindle Scribe, iPad mini 6, PocketBook InkPad Color 3
This is what I came up with (not tested on Windows or Linux):

PHP Code:
from logging import infobasicConfigINFO
from pathlib import Path
from re import fullmatch
from sys import argv

CONTENT_EXTENSIONS 
= {'.kfx''.azw''.azw1''.azw3''.pdf''.txt'}
TMP_REGEX r'\.tmp\d*_(ASC|PHL)'
basicConfig(level=INFO)


def remove_dir(folder):
    try:
        
Path(folder).rmdir()
        
info(f'Removed {folder}')
    
except OSError as ex:
        
info(f'** {ex} **')


def rmtree(root):
    for 
p in root.iterdir():
        if 
p.is_dir():
            
rmtree(p)
        else:
            
p.unlink()

    
root.rmdir()


scan_folder Path('/Volumes/Kindle/documents' if len(argv) == else argv[1])
if 
not scan_folder.is_dir():
    
info(f'Path {scan_folder} does not exist, quitting.')
    exit(
1)

content_file_stems set()
tmp_files = []
sdr_folders = []
for 
path_ in scan_folder.glob('**/*'):
    if 
'.sdr' in str(path_.parent) or 'updates' in path_.parent.parts:
        
# take no action on content in .sdr folders or /updates folder
        
continue
    if 
path_.is_dir():
        if 
path_.suffix == '.sdr':
            
sdr_folders.append(path_)
        else:
            
remove_dir(path_)
    else:
        if 
path_.suffix in CONTENT_EXTENSIONS:
            
content_file_stems.add((path_.parentpath_.stem))
        
elif fullmatch(TMP_REGEXpath_.suffix):
            
tmp_files.append(path_)

for 
tmp_file in tmp_files:
    if (
tmp_file.parenttmp_file.stemnot in content_file_stems:
        
Path(tmp_file).unlink()
        
info(f'Removed orphaned temp file {tmp_file}')

for 
sdr_folder in sdr_folders:
    if (
sdr_folder.parentsdr_folder.stemnot in content_file_stems:
        
rmtree(sdr_folder)
        
info(f'Removed orphaned .sdr folder {sdr_folder}'
All standard library, no external dependencies. Might need Python 3. On Mac you can just type 'python clean.py' once Kindle is plugged in. On Windows, you can use calibre-debug as interpreter (while supplying path argument like E:/documents).

It runs almost instantaneously, so I don't see any particular penalty to running it every time you plug Kindle in.

I haven't seen the tmp files except on one of my Kindles, so it's possible there are other patterns to look for.

I saw updates/ folder on a couple of them, with an .sdr folder inside. Not sure what it is for, but thought it best to leave it alone.

I think only /documents needs to be a target for cleanup. I would leave it to user to clean up screen captures in root, for example.

And I haven't seen any 'turds' in .documents folder so far (Scribe).

[Update] re-factored to use (preferred in Python 3) pathlib.

Last edited by tomsem; 06-22-2023 at 10:17 PM.
tomsem is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
.sdr folders generated from opened PDF files productivity01 KOReader 1 06-30-2022 02:39 PM
Import Data sees new empty folders as not empty mivetters Library Management 6 12-21-2019 03:18 PM
Hide or put all the .sdr folders in one place poorconsumer KOReader 6 11-20-2018 09:38 AM
Librarian Sync creates empty collections folders on Kindle Trups Kindle Developer's Corner 3 01-26-2017 08:38 AM
.SDR folders empty when loading MOBI covers on Kindle Paperwhite abarnard Library Management 1 12-25-2012 09:57 PM


All times are GMT -4. The time now is 08:35 AM.


MobileRead.com is a privately owned, operated and funded community.