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 04-08-2022, 09:39 PM   #1
shape
Member
shape began at the beginning.
 
shape's Avatar
 
Posts: 14
Karma: 10
Join Date: Apr 2022
Device: MacBook Pro (2019)
[MacOS] Renaming output files

I tried using Save to Disk and all the saved files still truncate. And not by just a few characters but by several lines that macOS allows me to add manually to the filename. Is there a setting that is causing it to truncate?

The “Automatically convert added books...” option in “Add Books” -> "Control the adding of books" -> "Adding actions" works so well that it's a shame not to be able to use this and also be able to control the filename output.
shape is offline   Reply With Quote
Old 04-08-2022, 10:34 PM   #2
BetterRed
null operator (he/him)
BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.
 
Posts: 21,731
Karma: 29711016
Join Date: Mar 2012
Location: Sydney Australia
Device: none
Quote:
Originally Posted by shape View Post
I tried using Save to Disk and all the saved files still truncate. And not by just a few characters but by several lines that macOS allows me to add manually to the filename. Is there a setting that is causing it to truncate?

The “Automatically convert added books...” option in “Add Books” -> "Control the adding of books" -> "Adding actions" works so well that it's a shame not to be able to use this and also be able to control the filename output.
See ==>> Save to disk

Quote:
You can control the file name and folder structure of files saved to disk by setting up a template in Preferences → Import/export → Saving books to disk. Also see The calibre template language
BR
BetterRed is offline   Reply With Quote
Advert
Old 04-08-2022, 10:44 PM   #3
shape
Member
shape began at the beginning.
 
shape's Avatar
 
Posts: 14
Karma: 10
Join Date: Apr 2022
Device: MacBook Pro (2019)
Thanks, but I don't see anything about filename truncation. The default naming template is sufficient but I don't see anything in the prefs or the manual about how to save the complete title & author names without truncating them.
shape is offline   Reply With Quote
Old 04-09-2022, 03:35 AM   #4
BetterRed
null operator (he/him)
BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.
 
Posts: 21,731
Karma: 29711016
Join Date: Mar 2012
Location: Sydney Australia
Device: none
It would help of you posted some screen shots as evidence of your claims that save to disk truncates your file names.

The Save to disk template defines how to construct save to disk paths and file names from the metadata.

Example - in the following screenshot you see a Russian version of Tolstoy's War and Peace in my Test library and the contents of the library book folder - note the transformation of the title and author names from Cyrillic into Latin-1.

Click image for larger version

Name:	Screenshot 2022-04-09 170109.jpg
Views:	326
Size:	172.3 KB
ID:	193175

These are my Save to disk preferences:

Click image for larger version

Name:	Screenshot 2022-04-09 170258.jpg
Views:	76
Size:	211.3 KB
ID:	193176

When I do a Save to disk this is what I get in my Saved Books folder :

Click image for larger version

Name:	Screenshot 2022-04-09 170446.jpg
Views:	75
Size:	75.3 KB
ID:	193177

Unfortunately I don't have an example of a truncated library file name - they a usually caused by subtitles, straplines, series names etc concatenated with the title in the title column.

BR
BetterRed is offline   Reply With Quote
Old 04-09-2022, 02:13 PM   #5
shape
Member
shape began at the beginning.
 
shape's Avatar
 
Posts: 14
Karma: 10
Join Date: Apr 2022
Device: MacBook Pro (2019)
Sure, I can post screenshots. Many of the ones that truncate actually do have the series name in the title in parenthesis. I didn't know this was a factor. But if I remove the parenthesis in Calibre and paste in more text it still cuts off the names of files and folders when saving to disk.

Here’s an example book title: “Enemy of the People: The Untold Story of the Journalists Who Opposed Hitler” by Terrence Petty. This is how it saves using the default “Save to Disk” template in Preferences w/ the latest Calibre 5.40 for macOS. In the 2nd image all folder/file names are truncated in the middle for some reason, even with the author folder which isn’t due to potentially having too many characters:

Click image for larger version

Name:	Calibre Library window.png
Views:	136
Size:	34.2 KB
ID:	193182

Click image for larger version

Name:	truncated names.png
Views:	135
Size:	46.6 KB
ID:	193183
shape is offline   Reply With Quote
Advert
Old 04-09-2022, 07:46 PM   #6
BetterRed
null operator (he/him)
BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.
 
Posts: 21,731
Karma: 29711016
Join Date: Mar 2012
Location: Sydney Australia
Device: none
Quote:
Originally Posted by shape View Post
Sure, I can post screenshots. Many of the ones that truncate actually do have the series name in the title in parenthesis. I didn't know this was a factor. But if I remove the parenthesis in Calibre and paste in more text it still cuts off the names of files and folders when saving to disk.

Here’s an example book title: “Enemy of the People: The Untold Story of the Journalists Who Opposed Hitler” by Terrence Petty. This is how it saves using the default “Save to Disk” template in Preferences w/ the latest Calibre 5.40 for macOS. In the 2nd image all folder/file names are truncated in the middle for some reason, even with the author folder which isn’t due to potentially having too many characters:

Attachment 193182

Attachment 193183
I use Windows 10, and I can save the same title with no truncation - even though Windows has a reputation of imposing greater restrictions on file system path lengths, and allowable characters than MacOS or Linux.

FWIW I would put the subtitle into a separate custom column as shown in the attached screen shots. The replacement of the ':' with '_' is because Windows does not allow < > : " / \ | ? * in file names.

I am going to put your issue in to its own thread and mark it as MacOS.

BR
Attached Thumbnails
Click image for larger version

Name:	0 Save Prefs.jpg
Views:	68
Size:	214.3 KB
ID:	193187   Click image for larger version

Name:	1 library.jpg
Views:	67
Size:	160.9 KB
ID:	193188   Click image for larger version

Name:	2 long title book folder.jpg
Views:	68
Size:	92.9 KB
ID:	193189   Click image for larger version

Name:	3 short title book folder.jpg
Views:	70
Size:	88.4 KB
ID:	193190   Click image for larger version

Name:	4 Saved Books.jpg
Views:	69
Size:	61.7 KB
ID:	193192  

Last edited by BetterRed; 04-09-2022 at 08:15 PM. Reason: Fix 5th image
BetterRed is offline   Reply With Quote
Old 04-09-2022, 09:36 PM   #7
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,359
Karma: 27182818
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Filenames have limited size. Dont try to shoehorn unlimited data into them.
kovidgoyal is offline   Reply With Quote
Old 04-09-2022, 10:23 PM   #8
shape
Member
shape began at the beginning.
 
shape's Avatar
 
Posts: 14
Karma: 10
Join Date: Apr 2022
Device: MacBook Pro (2019)
Quote:
Originally Posted by BetterRed View Post
The replacement of the ':' with '_' is because Windows does not allow < > : " / \ | ? * in file names.
It’s the same thing with certain special characters on Mac actually, including the colon but not the underscore. I would have liked to get the filenames to save without truncating before customizing the template, but how do I add the subtitle field?

@kovidgoyal: But why are they being cut off in the middle, and why would the author's name also be truncated in the folder name as "Petty,rrence"? I also explained that on Mac I can type in extra lines of text (dozens of additional characters), so the filename allowed by the OS is not the limitation.
shape is offline   Reply With Quote
Old 04-10-2022, 12:06 AM   #9
shape
Member
shape began at the beginning.
 
shape's Avatar
 
Posts: 14
Karma: 10
Join Date: Apr 2022
Device: MacBook Pro (2019)
The name cutting off as "Petty,rrence" looks buggy. Does a complete author name really qualify as unlimited data or were you referring to something else?
shape is offline   Reply With Quote
Old 04-10-2022, 12:09 AM   #10
BetterRed
null operator (he/him)
BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.
 
Posts: 21,731
Karma: 29711016
Join Date: Mar 2012
Location: Sydney Australia
Device: none
Quote:
Originally Posted by shape View Post
It’s the same thing with certain special characters on Mac actually, including the colon but not the underscore. I would have liked to get the filenames to save without truncating before customizing the template
What do you have in the Save to Disk template ?

And what is the path into which you are saving the books, try saving to a folder that's not deep in the file system hierarchy - e.g I am saving to:

Code:
C:\Users\<--my  name-->\Desktop\Saved Books
Quote:
Originally Posted by shape View Post
…but how do I add the subtitle field?
Preferences->Add your own columns:

Click image for larger version

Name:	Screenshot 2022-04-10 133203.jpg
Views:	62
Size:	52.3 KB
ID:	193193

BR
BetterRed is offline   Reply With Quote
Old 04-10-2022, 12:54 AM   #11
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: 46,243
Karma: 168983734
Join Date: Jul 2010
Location: Vancouver
Device: Kobo Sage, Libra Colour, Lenovo M8 FHD, Paperwhite 4, Tolino epos
Quote:
Originally Posted by shape View Post
@kovidgoyal: But why are they being cut off in the middle, and why would the author's name also be truncated in the folder name as "Petty,rrence"? I also explained that on Mac I can type in extra lines of text (dozens of additional characters), so the filename allowed by the OS is not the limitation.
calibre enforces a maximum path length regardless of OS. While APFS allows up to 255 characters for the filename length and a maximum path length of 1024, you run into the maximum path length (directory names plus filename) at a lot less than 1024 bytes with many OS (Windows for example), a common limit is 255 characters. Since calibre is multi-OS, it uses the shortest path length of the supported OS.

With Montery 12.3.1, here's what the OS reports as the limits:

Code:
davidb@Davids-VMMac ~ % getconf NAME_MAX /
255
davidb@Davids-VMMac ~ % getconf PATH_MAX /
1024
What you are showing is a path length of ~177 characters. If you have the Petty,rrence directory in the root of your hard drive, that's all she wrote. As it is, when I look at my Mac VM, the path to a calibre library is:
Code:
/Users/davidb/calibre/Calibre Library/
Adding this to your path, I get:

Code:
/Users/davidb/calibre/Calibre Library/Petty,rrence/Enemy of the People: The Untold Stthe Journalists Who Opposed Hitler/Enemy of the People_ The Untold Story of the Journalists Who Opposed Hitler - Terrence Petty.kfx
Depending on where you are saving to disk and the length of your user name, your path may be longer or shorter but likely longer.

Personally, I place subtitles into a column just for them and only use the first entry in the author(s) and author sort to keep lengths shorter. The author bits are more intended for anthologies where you can have multiple authors and path lengths rapidly get out of control.

Since I use mostly Kobo eReaders, I can send subtitle, series & multiple authors without needing to store them in the filename.

As Kovid said, try to keep filenames short. Write your book in the file and not in the filename.

Last edited by DNSB; 04-10-2022 at 01:03 AM.
DNSB is offline   Reply With Quote
Old 04-10-2022, 06:06 AM   #12
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,447
Karma: 8012886
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
You can control where/how truncation happens using the built-in template function shorten(val, left chars, middle text, right chars).

The function documentation is:
Quote:
Return a shortened version of val, consisting of `left chars` characters from the beginning of val, followed by `middle text`, followed by `right chars` characters from the end of the string. `Left chars` and `right chars` must be integers. For example, assume the title of the book is `Ancient English Laws in the Times of Ivanhoe`, and you want it to fit in a space of at most 15 characters. If you use {title:shorten(9,-,5)}, the result will be `Ancient E-anhoe`. If the field's length is less than left chars + right chars + the length of `middle text`, then the field will be used intact. For example, the title `The Dome` would not be changed.
The idea is that if filenames can be truncated because of path length then *you* decide where the truncation occurs. This ensures that the resulting values are predictable and consistent.

You can also choose to use only the first author, not all of them.

For example, this template uses the first 30 characters of the first author's name and the first 120 characters of the title, separated by a dash.
Code:
{authors:'shorten(sublist($, 0, 1, '&'), 30, '', 0)'} - {title:shorten(120,,0)}
You can get more exotic and use the first 15 characters of the first N authors separated however you want, then the title shortened however you want. This is easiest done with a General Program Mode template using a 'for' statement to loop through the authors. For example, the following template includes the first 4 authors shortened to 15 characters then a dash then the title shortened to 100 characters.
Code:
program:
	res = '';
	sep = '';
	for a in sublist($authors, 0, 4, '&') separator '&':
		res = res & sep & shorten(a, 15, '', 0);
		sep = ' & '
	rof;
	res & ' - ' & shorten($title, 100, '', 0)
NB: this template works in calibre 5.39 or later because it used the new '&' concatenation operator. If necessary you could back up to V5.10 (or so) by using the strcat() function.
chaley is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Renaming output files jay2thagd Library Management 3 02-05-2021 08:41 AM
Renaming files jay2thagd Introduce Yourself 1 02-04-2021 07:44 PM
Renaming files victormpalma Library Management 1 07-14-2020 09:55 AM
Problems renaming files skoobwoman iRex 0 08-20-2008 01:03 PM
Renaming files col Sony Reader 29 06-29-2007 10:10 AM


All times are GMT -4. The time now is 12:34 PM.


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