Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Library Management

Notices

Reply
 
Thread Tools Search this Thread
Old Yesterday, 11:33 PM   #1
natruok
Junior Member
natruok began at the beginning.
 
Posts: 6
Karma: 10
Join Date: Jul 2026
Device: none
Regex search & replace giving inconsistent results when pulling from "Path" field

I'm trying to pull the exact name of all files via the "Path" field, since Calibre handles special characters in the title differently on export, and there doesn't seem to be an option to directly export a list of the Path in the export catalogue option.

Whenever I do this, the title case of the words isn't always consistent for certain files, and since epub files are case-sensitive, it doesn't identify the file when the name doesn't match exactly.

I've tried pulling using the following templates in regex search and replace:
Code:
program:
p = $path;
re(p, '^.*/(.+)\s\([0-9]+\)','\1')
Code:
program:
p = $path;
p = re(p,".+\/","");
p = re(p,"\s\([0-9]+\)$","");
Code:
python:
import re
def evaluate(book, context):

	p = book.get('path')
	p = re.search('(?<=./).+(?=\s\([0-9]+\))',p)
	return p.group(0)
I can't identify which files/why certain ones have issues, but what happens is:
  1. In the template box, it will show appropriately what I expect the result to be
  2. When I'm outside the template box, I get the error "S/R TEMPLATE ERROR Interpreter: Unknown field 'path' - line number #"
  3. After I run the search and replace, it will create a result that is either correct or incorrect — in this specific case with a one-word title, the first letter will be either capitalized or not; in the case of multi-word titles (can't find an exact example right now), the original title & path might be in Title Case, but the result will be either Title Case or only first letter of the entire title capitalized
  4. Each time I run the search and replace, when only one file is selected, it will "refresh" all the other results that fall under this same error. So when there are multiple errors, after I've fixed one, when I go to fix another, it will cause the error in the earlier one again.

It doesn't only occur with cases where I have duplicate titles, but it's easiest to demonstrate with that.

In the screenshot, the first time I run any of the searches above, it will show the correct "Amortentia", which is capitalized. Then if I preview it for the second line, it will show the correct "amortentia" in lower case for the second file, and after I run the search and replace, it will change both of them to "amortentia". And then if I go back to try and change the first one, it will again change both to "Amortentia".

I am running this on my entire library, so the results continue to fluctuate until the library is done.

Is there something that's wrong with my regex searches, or the way the Path column is handled?

In the image, the first Path column is the default calibre column, and the second Path column is custom column where I've run the search and replace.
Attached Thumbnails
Click image for larger version

Name:	Screenshot 2026-09-08 at 20.04.33.png
Views:	8
Size:	41.3 KB
ID:	225794  
natruok is offline   Reply With Quote
Old Yesterday, 11:37 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: 46,475
Karma: 29634066
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Not sure what you are trying to do. I dont know what case sensitivity of epub files has to do with file **names**? And you can absolutely export paths using the catalog feature.
kovidgoyal is offline   Reply With Quote
Advert
Old Today, 12:21 AM   #3
natruok
Junior Member
natruok began at the beginning.
 
Posts: 6
Karma: 10
Join Date: Jul 2026
Device: none
I'm essentially trying to compare a list of files currently in my calibre library against the actual files in my computer because something went weird with my file manager ... still figuring that part out.

But I can't just export the title, because Calibre changes certain special characters in the title name to _ instead.

Quote:
Originally Posted by kovidgoyal View Post
And you can absolutely export paths using the catalog feature.
Maybe I'm going crazy but I've looked at this list again and again and I don't see the Path option to be selected for export? (Sorry, a lot of custom columns ...)
I've attached screenshots, unless it's somewhere else I'm supposed to be looking?
Attached Thumbnails
Click image for larger version

Name:	Screenshot 2026-09-08 at 21.08.33.png
Views:	10
Size:	271.6 KB
ID:	225796   Click image for larger version

Name:	Screenshot 2026-09-08 at 21.09.16.png
Views:	8
Size:	254.3 KB
ID:	225797   Click image for larger version

Name:	Screenshot 2026-09-08 at 21.15.42.png
Views:	6
Size:	228.3 KB
ID:	225799  
natruok is offline   Reply With Quote
Old Today, 12:36 AM   #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: 46,475
Karma: 29634066
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Use the dedicated library maintenance tool for that. Right click the library icon in the main calibre toolbar and choose Library maintenance
kovidgoyal is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
search & replace doesnt work with "newlines" in PDF to MOBI conversion fred410 Conversion 0 02-28-2021 05:13 PM
5.1.0 bug in "search and replace" regex field Snowman Library Management 4 10-05-2020 10:17 AM
Destination "uuid" in Search & Replace Metdata dialog halloleo Library Management 8 03-08-2020 10:50 PM
Default "find" for Search/Replace regex functions vr8ce Editor 14 02-02-2018 10:41 AM
Missing "function mode" for editor's Search & Replace atux Editor 3 01-17-2016 08:40 AM


All times are GMT -4. The time now is 09:01 PM.


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