1

I have a very large eBook library. The structure is as follows:

/Library
   /Author Name
      /Book Name
         /{.pdf .mobi .epub eBook files}, {.opf metadata files}, {.jpg book cover files}

About 15% of the 11,000 "Book Name" folders I have contain only a .opf file and sometimes a .jpeg/.jpg/.png/.gif cover file, with no eBook files.

I would like to write something that can find folders that do not contain an eBook file (.pdf/.epub/.mobi) and delete the contents of the "Book Name" folder, the "Book Name" folder itself, and if it is the only "Book Name" folder in the "Author Name" folder, delete the "Author Name" folder, as well.

I am completely knew to this, but will continue to research and post my results here if someone else can't help me out.

1 Answer 1

1

Assuming you're on a recent Windows... I'd break this in two steps.

CD to "Library" and...

  1. Remove files in folders with no ebooks:

    for /f "delims=" %F in ('dir /s/b/a-d *.opf') do dir /b "%~pF*.pdf" "%~pF*.epub" "%~pF*.mobi" || del "%~pF*.*"
    

    (If you have many files to erase, add the /q option to del not to have prompts)

  2. Recursively delete empty directories in Windows:

    for /f "delims=" %D in ('dir /s/b/ad ^| sort /r') do rd "%D"
    
1
  • Thanks Salvo, what a great solution. I'm going to try it out soon.
    – Bob
    Jun 26, 2015 at 1:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .