Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Sigil

Notices

Reply
 
Thread Tools Search this Thread
Old 10-03-2024, 11:13 PM   #1
KarlG
Connoisseur
KarlG began at the beginning.
 
Posts: 62
Karma: 10
Join Date: Mar 2024
Device: none
Regex Rename Issue

Wasn't sure if I should open a new theme or just add to this one.

Anyway, I wanted to do a mass regex rename of some image files

As you can see the results aren't as expected. The preview shows the correct result but when I actually click ok it turns out completely different.

Is this an error in Sigil or am I doing something wrong?
Attached Thumbnails
Click image for larger version

Name:	error1.png
Views:	111
Size:	7.2 KB
ID:	211187   Click image for larger version

Name:	error2.png
Views:	120
Size:	50.1 KB
ID:	211188   Click image for larger version

Name:	error3.png
Views:	127
Size:	82.8 KB
ID:	211189   Click image for larger version

Name:	error4.png
Views:	115
Size:	12.5 KB
ID:	211190  
KarlG is offline   Reply With Quote
Old 10-04-2024, 01:05 AM   #2
DNSB
Bibliophagist
DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.
 
DNSB's Avatar
 
Posts: 40,521
Karma: 156983616
Join Date: Jul 2010
Location: Vancouver
Device: Kobo Sage, Libra Colour, Lenovo M8 FHD, Paperwhite 4, Tolino epos
If I remember correctly, you are matching any . in the original filename and replacing it with fig. This would include the . between the chapter number and the image number as well as the . prior to jpg.

A search string something like ch(.*?)\.(.*?) and a replacement string of ch\1fig\2 is likely to be closer to what you need.
DNSB is offline   Reply With Quote
Advert
Old 10-04-2024, 02:02 AM   #3
KarlG
Connoisseur
KarlG began at the beginning.
 
Posts: 62
Karma: 10
Join Date: Mar 2024
Device: none
Quote:
Originally Posted by DNSB View Post
If I remember correctly, you are matching any . in the original filename and replacing it with fig. This would include the . between the chapter number and the image number as well as the . prior to jpg.

A search string something like ch(.*?)\.(.*?) and a replacement string of ch\1fig\2 is likely to be closer to what you need.
Hi David,

The problem is, there ISN'T a . before jpg. It's just _jpg
KarlG is offline   Reply With Quote
Old 10-04-2024, 07:08 AM   #4
DiapDealer
Grand Sorcerer
DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.
 
DiapDealer's Avatar
 
Posts: 28,040
Karma: 199464182
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
Quote:
Originally Posted by KarlG View Post
The problem is, there ISN'T a . before jpg. It's just _jpg
And that may be part of the problem. .01_jpg is not a proper file extension. That may be tripping up the regex rename routine. I'll have to take a look.
DiapDealer is offline   Reply With Quote
Old 10-04-2024, 07:38 AM   #5
DiapDealer
Grand Sorcerer
DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.
 
DiapDealer's Avatar
 
Posts: 28,040
Karma: 199464182
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
Definitely a bug if the preview does not match the end result. I may move this to its own thread since it's not really related to the original F&R minimal match topic.

Last edited by DiapDealer; 10-04-2024 at 07:47 AM.
DiapDealer is offline   Reply With Quote
Advert
Old 10-04-2024, 08:39 AM   #6
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 8,158
Karma: 5450818
Join Date: Nov 2009
Device: many
It seems none of the original files had a valid file extension?

The RenameResourceList code in OPFModel, extracts the file extension from the original file name, runs the rename, then adds in the extensions.

See https://github.com/Sigil-Ebook/Sigil...Model.cpp#L346

But since no actual file extension existed, it extracted the .01_jpg, .02_jpg, etc as file extensions.

So to handle this case properly, you should use normal rename to add the proper .jpg file extension first to all files, then use the RegexRenamer with the find text properly modified.
Or take the results of the REXRenamer and then run it through a normal rename of file extendions last. Either should work.

It is important that proper file extensions exist so that they can act as fallbacks for missing media-types.

Last edited by KevinH; 10-04-2024 at 09:12 AM.
KevinH is offline   Reply With Quote
Old 10-04-2024, 09:01 AM   #7
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 8,158
Karma: 5450818
Join Date: Nov 2009
Device: many
So not sure if this is a bug or not as there were no valid file extensions to begin with, which the current regex renamer code expects. We might have to modify the renamer code to compare the extracted file extension to a list of known valid file extensions, and then handle the case of invalid file extensions in some other way.

That might work. But doing the rename in 2 passes (as described above) should do the trick.

Last edited by KevinH; 10-04-2024 at 09:13 AM.
KevinH is offline   Reply With Quote
Old 10-04-2024, 09:16 AM   #8
DiapDealer
Grand Sorcerer
DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.
 
DiapDealer's Avatar
 
Posts: 28,040
Karma: 199464182
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
I agree it may not technically be a bug in the renaming algorithm itself. I was more referring to the fact the regex rename preview is showing something other than what the actual results are turning out to be.
DiapDealer is offline   Reply With Quote
Old 10-04-2024, 09:30 AM   #9
DiapDealer
Grand Sorcerer
DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.
 
DiapDealer's Avatar
 
Posts: 28,040
Karma: 199464182
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
In the meantime, the OP still should be able to achieve what they want with a regex of:
Code:
\.(\d+)_jpg
and a replacement of:
Code:
fig\1.jpg
That keeps both the chapter number and the figure number and places the proper .jpg extension at the end.

Last edited by DiapDealer; 10-04-2024 at 09:32 AM.
DiapDealer is offline   Reply With Quote
Old 10-04-2024, 09:33 AM   #10
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 8,158
Karma: 5450818
Join Date: Nov 2009
Device: many
But that only happens when no valid file extensions exists. We could copy the code into the REXRenamer Table to split off the file extension (just like the current shared rename code does now) so they would exactly match even in this strange (no valid file extension) case but then I think the 01, 02, 03 info would get lost, preventing the 2 pass approach from working. But I can not test that to verify.
KevinH is offline   Reply With Quote
Old 10-04-2024, 09:53 AM   #11
DiapDealer
Grand Sorcerer
DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.
 
DiapDealer's Avatar
 
Posts: 28,040
Karma: 199464182
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
Yeah, I'm just not sure what would be best here. I'm leaning toward simply throwing a warning that the regex renamer can't continue whenever the regex matches a file without a valid extension. It may be pointless to try and accommodate invalid extensions. Surely these files are going cause problems in other places, no?
DiapDealer is offline   Reply With Quote
Old 10-04-2024, 03:34 PM   #12
DNSB
Bibliophagist
DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.DNSB ought to be getting tired of karma fortunes by now.
 
DNSB's Avatar
 
Posts: 40,521
Karma: 156983616
Join Date: Jul 2010
Location: Vancouver
Device: Kobo Sage, Libra Colour, Lenovo M8 FHD, Paperwhite 4, Tolino epos
Quote:
Originally Posted by KarlG View Post
Hi David,

The problem is, there ISN'T a . before jpg. It's just _jpg
I suspect that you have read enough on this topic from KevinH and DiapDealer but, having files without valid file extensions is Not A Good Idea.
DNSB is offline   Reply With Quote
Old 10-06-2024, 01:51 AM   #13
KarlG
Connoisseur
KarlG began at the beginning.
 
Posts: 62
Karma: 10
Join Date: Mar 2024
Device: none
Quote:
Originally Posted by DNSB View Post
I suspect that you have read enough on this topic from KevinH and DiapDealer but, having files without valid file extensions is Not A Good Idea.
In general I would agree, but as all my systems are running Linux file extensions are not always necessary.

Sigil is a multi-platform environment though, so we have to take Windows systems into account.
KarlG is offline   Reply With Quote
Old 10-06-2024, 06:47 AM   #14
DiapDealer
Grand Sorcerer
DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.DiapDealer ought to be getting tired of karma fortunes by now.
 
DiapDealer's Avatar
 
Posts: 28,040
Karma: 199464182
Join Date: Jan 2010
Device: Nexus 7, Kindle Fire HD
It's not about Linux vs Windows (or even Sigil), it's about epub best practices. You won't find an epub out there in the wild that doesn't use proper file-type extensions internally.
DiapDealer is offline   Reply With Quote
Old 10-06-2024, 08:19 AM   #15
KarlG
Connoisseur
KarlG began at the beginning.
 
Posts: 62
Karma: 10
Join Date: Mar 2024
Device: none
Quote:
Originally Posted by DiapDealer View Post
It's not about Linux vs Windows (or even Sigil), it's about epub best practices. You won't find an epub out there in the wild that doesn't use proper file-type extensions internally.
I see. Good to know...
KarlG is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
pdf regex question - regex that wraps to a new line flyash Conversion 1 09-05-2021 10:00 AM
Class Rename Issue Paulie_D Editor 2 03-29-2021 01:09 PM
Predefined regex for Regex-function sherman Editor 3 01-19-2020 06:32 AM
regex - issue with spaces? cybmole Editor 43 12-31-2013 01:49 PM
regex Issue when Importing river Calibre 3 06-16-2009 12:03 PM


All times are GMT -4. The time now is 01:07 AM.


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