|  07-10-2025, 02:00 AM | #16 | |
| Connoisseur            Posts: 68 Karma: 11226 Join Date: Mar 2022 Device: Kobo Libra 2, Aura H2O | 
				
				Random number of characters in truncated file names
			 Quote: 
  The issue under windows 11 is as follows: if a book has a relatively long title in metadata (e.g. 70-75 characters) when it is added to Calibre library, the file name automatically generated by Calibre would be truncated to a random number of characters.  Some file names would become 51 characters long, others - 55 characters, etc. When copied to devices (in my case Kobo Sage), the file names are not truncated at all (since they are less than 250 characters). Hence the files between the windows library and the device are named differently and have different hush numbers.  This causes all kinds of problems when I am trying to synchronize of metadata generated by Koreader, etc. Since the same books are treated as different ones. How can I have exactly the same file names between the main library in windows and file names copied to non-windows devices? E.g. if due to whatever limitation the book file in Calibre is 51 character long, then it would be transferred to connected devices without any changes. I would really appreciate your insight on how to resolve this. | |
|   |   | 
|  07-10-2025, 03:12 AM | #17 | 
| Bibliophagist            Posts: 48,078 Karma: 174315300 Join Date: Jul 2010 Location: Vancouver Device: Kobo Sage, Libra Colour, Lenovo M8 FHD, Paperwhite 4, Tolino epos | 
			
			The file name sent to your ereader should be set from metadata depending on the template you use when saving. The name in the calibre library is not really relevant. Basically use the calibre library directory as a black box and stop peeking under it's skirts. You may want to look at the location for your calibre library and move it to a location that has a shorter path. i.e. D:\Calibre\<library name>. OTOH, out of perhaps morbid curiosity, what is a hush number? You may want to disable updating metadata in the file when it is being sent from calibre to your Sage since that can and will modify the file hash. Depending on what file system you are using, other limitations may be present. If you are trying to use very long file paths, have you set FileSystem LongPathsEnabled to enabled in the registry and does the application have set longPathAware true in the application's manifest? | 
|   |   | 
|  07-10-2025, 06:32 AM | #18 | 
| Still reading            Posts: 14,975 Karma: 111111111 Join Date: Jun 2017 Location: Ireland Device: All 4 Kinds: epub eink, Kindle, android eink, NxtPaper | 
			
			And with long paths Backups will fail. Actually backups and copies can fail even with regular paths if the names of directories or files are too long.
		 | 
|   |   | 
|  07-10-2025, 01:22 PM | #19 | |||||
| Connoisseur            Posts: 68 Karma: 11226 Join Date: Mar 2022 Device: Kobo Libra 2, Aura H2O | 
			
			Thanks for your response. Please see below. Quote: 
 Quote: 
 Quote: 
     Quote: 
 Quote: 
 I wish there was a setting "keep device file names the same as in Calibre library" This would be ideal | |||||
|   |   | 
|  07-10-2025, 01:57 PM | #20 | |
| Resident Curmudgeon            Posts: 80,727 Karma: 150249619 Join Date: Nov 2006 Location: Roslindale, Massachusetts Device: Kobo Libra 2, Kobo Aura H2O, PRS-650, PRS-T1, nook STR, PW3 | Quote: 
 | |
|   |   | 
|  07-10-2025, 02:09 PM | #21 | |
| Grand Sorcerer            Posts: 12,525 Karma: 8065948 Join Date: Jan 2010 Location: Notts, England Device: Kobo Libra 2 | Quote: 
 On the other hand, you can use the format_paths() template function to get the current library file path for a book's formats and use that when sending to your device. Of course this won't help with long path names. | |
|   |   | 
|  07-10-2025, 02:59 PM | #22 | ||
| Connoisseur            Posts: 68 Karma: 11226 Join Date: Mar 2022 Device: Kobo Libra 2, Aura H2O | Quote: 
 Quote: 
 Code: C:\VAULTS\ Code: <dc:title>Исцеление духовных болезней</dc:title> Code: C:\VAULTS\CalibVault\Zhan-Klod Larshie\Istsielieniie dukhovnykh boliezniei (517)\Istsielieniie dukhovnykh boliez - Zhan-Klod Larshie.epub Code: E:\Zhan-Klod Larshie\Istsielieniie dukhovnykh boliezniei - Zhan-Klod Larshie.epub Code: "Istsielieniie dukhovnykh boliez - Zhan-Klod Larshie.epub" Code: "Istsielieniie dukhovnykh boliezniei - Zhan-Klod Larshie.epub" Last edited by edojan; 07-10-2025 at 03:01 PM. | ||
|   |   | 
|  07-10-2025, 03:04 PM | #23 | |
| Connoisseur            Posts: 68 Karma: 11226 Join Date: Mar 2022 Device: Kobo Libra 2, Aura H2O | Quote: 
   | |
|   |   | 
|  07-10-2025, 03:30 PM | #24 | 
| Grand Sorcerer            Posts: 12,525 Karma: 8065948 Join Date: Jan 2010 Location: Notts, England Device: Kobo Libra 2 | 
			
			As I said, calibre chooses how to name files using whatever algorithm is in the release when the file is created. The algorithm is complex, taking into consideration lengths of the title, authors, path to library, and library ID. You cannot turn off calibre's actions when metadata changes. Others have tried to reproduce calibre's naming with templates. To my knowledge, during 15 years none have been successful.  Your only chance is to use the calibre-generated name, available via format_paths(). Or   | 
|   |   | 
|  07-10-2025, 03:59 PM | #25 | 
| Connoisseur            Posts: 68 Karma: 11226 Join Date: Mar 2022 Device: Kobo Libra 2, Aura H2O | |
|   |   | 
|  07-10-2025, 04:27 PM | #26 | |
| Grand Sorcerer            Posts: 12,525 Karma: 8065948 Join Date: Jan 2010 Location: Notts, England Device: Kobo Libra 2 | Quote: 
 | |
|   |   | 
|  07-10-2025, 05:53 PM | #27 | 
| Grand Sorcerer            Posts: 12,525 Karma: 8065948 Join Date: Jan 2010 Location: Notts, England Device: Kobo Libra 2 | 
			
			The formats_path() function has problems if authors contain a comma. I need to fix this in base calibre. In the meantime, this python template returns the basename of the book file Code: python:
def evaluate(book, context):
	import os
	from calibre.library import current_library_path
	fmt_metadata = book.get('format_metadata')
	if fmt_metadata:
		for v in fmt_metadata.values():
			# A calibre format name is roughly "author/title (id)/title - author.extension"
			# We want to return the last segment, stripping off the author and title 
			# directory names and the extension, leaving just the basename of the book file
			f = v['path']
			return f[f.rfind(os.sep)+1:f.rfind('.')] 
	else:
		raise ValueError('Book "{}" has no formats'.format(book.title)) | 
|   |   | 
|  07-10-2025, 06:22 PM | #28 | |
| Connoisseur            Posts: 68 Karma: 11226 Join Date: Mar 2022 Device: Kobo Libra 2, Aura H2O | Quote: 
 I really appreciate it. The problem is that I am not very technical. Would it be too much to ask for more detailed instructions? I have tried entering the code in the template editor, but it produces an error. What steps am I missing? | |
|   |   | 
|  07-10-2025, 06:38 PM | #29 | 
| Connoisseur            Posts: 68 Karma: 11226 Join Date: Mar 2022 Device: Kobo Libra 2, Aura H2O | 
			
			here is the screenshot
		 | 
|   |   | 
|  07-10-2025, 10:39 PM | #30 | 
| Grand Sorcerer            Posts: 12,525 Karma: 8065948 Join Date: Jan 2010 Location: Notts, England Device: Kobo Libra 2 | 
			
			That error is harmless, caused by the template dialog not having a real book to work with. It will work when it us run "for real" -- when sending to the device. This version removes the error. Code: python:
def evaluate(book, context):
	import os
	from calibre.library import current_library_path
	fmt_metadata = book.get('format_metadata')
	if fmt_metadata:
		for v in fmt_metadata.values():
			# A calibre format name is roughly "author/title (id)/title - author.extension"
			# We want to return the last segment, stripping off the author and title 
			# directory names and the extension, leaving just the basename of the book file
			f = v['path']
			return f[f.rfind(os.sep)+1:f.rfind('.')] 
	else:
		return 'title - author' | 
|   |   | 
|  | 
| 
 | 
|  Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post | 
| Problem with Calibre's folder structure and long names in Windows | crixtiano | Calibre | 1 | 07-28-2017 02:05 PM | 
| Calibre taking a long, long time to update metadata on sony prs650 | hydin | Calibre | 5 | 06-05-2012 12:21 AM | 
| Is there anything in Calibre that can fix long file names automatically? | dmunson | Calibre | 4 | 02-05-2012 06:12 PM | 
| File Names to long? | JTAL604622 | Calibre | 5 | 08-31-2011 03:21 AM | 
| Files with long names? | cmhsieh54 | iRex | 0 | 08-05-2009 12:43 PM |