I was checking my epubs directories, and identified a problem.
I have 4466 .epub files and in addition i have 4473 .opf files. My calibre software usually creates 1 .opf file for each .epub file all in individual sub directories - so it looks as if I have got 7 duplicate/extra opf files in error.
Calibre'smaintenance software check tells me that everything is OK, but that must almost certainly be wrong
It seems likely that the most obvious solution is that some folders have two or more .opf files (the other alternative is that there is no .epub file in a directory).
As a first check, I was hoping to write a batch file to check a parent directory plus all sub-directories. If there are any files in a directory, I would like to create a list of all directories where there is more than 1 .opf file, or less than 1 .epub file.
Writing this is beyond me however. I tried a few Google searches and although I found something close, I could not get near enough, or even get it to work so I could amend it.
I'd therefore appreciate any help to point me at a solution.
Many thanks
Colin
Count files problem
Moderator: DosItHelp
Re: Count files problem
EDITED: There was a flaw in the code. Try this instead:
c:\folder is your main folder.
It could be expanded to check if more than 1 epub files exist in a folder
c:\folder is your main folder.
It could be expanded to check if more than 1 epub files exist in a folder
@echo off
for /d /r "c:\folder" %%a in (*) do (
if not exist "%%a\*.epub" echo "%%a" is missing an epub file
dir "%%a\*.opf" /b /a-d |find /c /v ""|findstr "^1$">nul || echo "%%a" has the wrong number of opf files
)
Re: Count files problem
Many thanks for your help, and so quickly too.
I'm just away to run it on my other PC and I'll let you know the outcome.
Colin
I'm just away to run it on my other PC and I'll let you know the outcome.
Colin
Re: Count files problem
Hi foxdrive
I replaced the drive location as instructed, and let it run
There is a problem with the logic somewhere, as I could see on screen that I was getting masses of results.
I re-directed the echo command to two separate txt files one for the epub, one for the opf files, and posted the results into excel to get a count. Each one had 5277 lines of text, and when I checked the parent folder, it reported exactly 5277 folders.
So the logic is reporting an error in exactly 100% of cases, I can't work out for myself what is actually happening tho.
I created the batch file by cut & paste, so there should not have been an error there, and I also pasted in the parent folder, so again it should be correct (and I can see from the output that it is).
The way the folder structure is created, the first level of sub directories are for author names and each has no files , just a further sub-directory for each book. So there should be some 800 directories with no files of any type.
Colin
I replaced the drive location as instructed, and let it run
There is a problem with the logic somewhere, as I could see on screen that I was getting masses of results.
I re-directed the echo command to two separate txt files one for the epub, one for the opf files, and posted the results into excel to get a count. Each one had 5277 lines of text, and when I checked the parent folder, it reported exactly 5277 folders.
So the logic is reporting an error in exactly 100% of cases, I can't work out for myself what is actually happening tho.
I created the batch file by cut & paste, so there should not have been an error there, and I also pasted in the parent folder, so again it should be correct (and I can see from the output that it is).
The way the folder structure is created, the first level of sub directories are for author names and each has no files , just a further sub-directory for each book. So there should be some 800 directories with no files of any type.
Colin
Re: Count files problem
I edited the code soon after you posted that you were going to try it.
This code adds a feature to ignore folders which have no files.
This code adds a feature to ignore folders which have no files.
Code: Select all
@echo off
for /d /r "c:\folder" %%a in (*) do (
dir "%%a" /b /a-d 2>nul |find /c /v "" |findstr "^0$" >nul || (
if not exist "%%a\*.epub" echo "%%a" is missing an epub file
dir "%%a\*.opf" /b /a-d |find /c /v ""|findstr "^1$">nul || echo "%%a" has the wrong number of opf files
)
)
pause
Re: Count files problem
Thank you very much
That worked EXACTLY as I required.
Manay many thanks
Colin
That worked EXACTLY as I required.
Manay many thanks
Colin