Dan,

I have built on your answer to develop the following, which only names the
resulting files "xx.sfx" or " x.sfx", where the x's are digits, and depends
on whether the number of files is a 2-digit number. My results relies
heavily on my understanding that the first value of `fn` in your code is a
boxed list of qualifying file names that I can use to count the files.

The key difference is that I use the following verb, `numb`, which I have
not reflected upon, nor attempted to refine.

nodd=: >.@-:
neven=: <.@-:
odd=: >:@+:@i.@nodd
even=: 2+|.@:+:@i.@neven
NB. used on the last line of flipOddPages
numb=: 2&":@ (odd,.@,even)"0


flipOddPages=: verb define
'comb png' flipOddPages y
:
NB.y=directory to scan, x=file prefix and suffix
NB. all directory names must not include spaces
'pfx sfx'=. 2 {. (;:^:(0=L.) x),<'png'
dir=. (,'/'-.{:)y
NB. above, use PATHJSEP_j_ (or PATHSEP_j_ in J6)

NB. Scan directory
fn=. {. |: 1!:0 jpath dir,pfx,'*',sfx
n=.#fn  NB. count the files
NB. norm contributed by Raul to deal with 2-digit names
norm=. 0 ". (#pfx) }. (-#sfx) }. ]
fn=. (/: norm&>) fn

fn ,.<"1 (numb n),"1'.',sfx

)

Does this seem to agree with your ideas?
Thanks, so much,



On Sun, Dec 22, 2013 at 3:36 PM, Dan Bron <[email protected]> wrote:

> Brian, I haven't read your report below closely, but bear in mind that the
> code I posted assumes pages are counted from zero. In fact, it enforces
> this assumption by converting "foo.png" explicitly to "foo 0.png".
>
> I also didn't get a chance to look into the earlier report about
> out-of-order indices, though I'm quite surprised that explicit sorting was
> required to fix it. My goal in designing (|@:- 2&| * (- 2&|)@#) and earlier
> versions was specifically to create a purely arithmetic,
> ordering-independent function.
>
> In other words I set out to define a scalar dyad, which, given the input
> page number and the total number of pages in the book, would produce the
> corrected page # for odd pages.  That it requires the input _array_ to be
> sorted confuses me: except for the #, none of its components can even see
> the "array", per se (only the individual scalars).
>
> BTW, that # is the first place you should look to permit one-based page
> numbering.
>
> -Dan
>
> PS:  The reason the rest of the code is "so clear" vs np is because the
> focus of my effort was a compact, elegant way to express np.  The rest of
> the verb was just stamp-collecting (so I didn't focus on making it
> "interesting" :) .  I'm sure there are straightforward but unexciting ways
> to express the core page flipping verb, particularly at rank 1 .
>
>
>
>
>
> --
(B=)
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to