Sorry, I should have tested my code on odd-length arguments as well as even.
Thanks to Raul's help on twitter, we can fix the bug by using (|@:- 2&| * (-
2&|)@#) in place of (+ 2&| * #-+:) .
To address the '\' vs '/' issue, I suppose we should standardize by using
PATHJSEP_j_ (or PATHSEP_j_ in J6-) in place of raw '\'.
I'm not sure what changes to make to the verb, if any, to get it to work
properly on the example directory you gave. I suspect you're getting blank
output because it's not scanning the directory you want it to. I suggest
you embed a line like
smoutput jpath dir,pfx,'*.',sfx
somewhere in the verb, to see what directory J's looking in. If the
directory looks right, but you're still getting blank output, then the
filename pattern may be wrong.
If the directory doesn't look right, remember that ~ is being expanded by
jpath, not your shell. In your shell, ~ means "home", i.e. your user
directory. In J, it means your "J home", which is often a subdirectory of
your user directory. Try using an absolute path (starting with '/') to
force J to look in the right place. If that works, you can experiment with
jpath and USERFOLDERS to figure out if you can use a shorter synonym.
If the directory looks right, but the pattern doesn't, then you can try
experimenting with the LHA to flipOddPages. By default, the verb will look
for files using the pattern 'comb*.png'. You can adjust either the prefix
('comb') or the suffix ('png') or both, using the x argument.
For example, in your original message, you listed a number of files whose
names started with 'combined', (as in 'combined 4.png'), so you could say:
'combined' flipOddPages some_directory
You also discussed generating PDFs instead of PNG files; in that case, you
could say:
'combined pdf' flipOddPages some_directory
or
('combined';'pdf') flipOddPages some_directory
In any case, I don't think we're far off. Should just take some
experimentation and maybe a few adjustments to the code.
-Dan
flipOddPages=:verb define
'comb png' flipOddPages y
:
NB.y=directory to scan, x=file prefix and suffix
'pfx sfx'=.2 {. (;:^:(0=L.) x),<'png'
dir =. (,PATHJSEP_j_-.{:)y NB. Use PATHSEP_j_ in J6 and earlier
versions
smoutput jpath dir,pfx,'*.',sfx
NB. Scan directory
fn =. {. |: 1!:0 jpath dir,pfx,'*',sfx
NB. Zero-fill here will convert comb.png to comb 0.png
NB. The increments account for the space after comb and
NB. the dot before png respectively.
pn=.0 ".&> (1+#pfx) }.&.> (-1+#sfx)}.&.> fn
NB. Reverse order of odds
pn=. (|@:- 2&| * (- 2&|)@#) pn
NB. Table of old-filename, new-filename
fn ,. <@;"1 (<pfx,' '),.(":&.> pn),.<'.',sfx
)
NB. Can remove smoutput line once you're done debugging
NB. Usage examples:
flipOddPages '~temp\archive1'
'combined' flipOddPages '~temp\archive1'
'combined pdf' flipOddPages '~temp\archive1'
('combined';'pdf') flipOddPages '~temp\archive1'
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Brian Schott
Sent: Saturday, December 14, 2013 1:17 PM
To: Chat forum
Subject: Re: [Jchat] Fwd: Archive j
Raul and Dan,
Yes, when I change '\' to '/' Dan's flipOddPages works great in my j temp
folder. I am struggling making it work in a folder like the one I showed,
but that is temporary, I hope. When I do, I get a blank line output.
I also want to see how to deal with an odd number of pages.
Great app, though.
Thanks, again.
--
(B=)
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm