View Single Post
Old 03-07-2016, 01:31 PM   #9
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
Posts: 19,421
Karma: 85400180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
Quote:
Originally Posted by fidvo View Post
FWIW, here is my Save to Disk template:

Code:
program:

switch(current_library_name(),
  'Library - Main',
  template('{#path:re(\.,/)}/{series_index:0>3s||_}{#subseries}{#subseries_index:0>3s||_}{title}'),
  'Library - Special',
  template('{#path:re(\.,/)}/{series_index:0>3s||_}{title}'),
  'Library - In Progress',
  template('{author_sort}/{series}/{series_index:0>3s}_{title}'),
  template('{#path:re(\.,/)}/{#seriesid:re(\.,/)}{#titleid:re(\.,/)}'))
Note that "path" is a custom field I set up, not the path to the file. (In hindsight I should have named it something else)
Invoking templates inside GPM is ugly (and slower) why not use this?

Code:
program:

# Initialize repetitive and/or complicated values for later use.
path = re(
	field('#path'),
	'\.',
	'/'
);
seriesid = re(
	field('#seriesid'),
	'\.',
	'/'
);
titleid = re(
	field('#titleid'),
	'\.',
	'/'
);

sidx = finish_formatting(
	field('series_index'),
	'0>3s',
	'',
	'_'
);
subsidx = finish_formatting(
	field('#subseries_index'),
	'0>3s',
	'',
	'_'
);

# Compute final return value.
switch(
	current_library_name(),
	'Library - Main',
	strcat(
		path, '/', sidx, field('#subseries'), subsidx, field('title')
	),
	'Library - Special',
	strcat(
		path, '/', sidx, field('title')
	),
	'Library - In Progress',
	strcat(
		field('author_sort'), '/', field('series'), '/', sidx, field('title')
	),
	strcat(
		path, '/', seriesid, titleid
	)
)
eschwartz is offline   Reply With Quote