Picking out base file name

Discussion in 'Rebol' started by swhite, Apr 23, 2010.

  1. swhite

    swhite Member

    I put this on the mailing list, and it seems to have disappeared. I am wondering where REBOL support questions are going these days. Anyway...

    I am interested in picking off the "base" part of a file name, that is, the part up to the "extension," that is, the part that begins with the dot. For example, the base file name of "abc.def" would be "abc". I realize there is the "suffix?" command for the ".def" but I want the first part. Also, I am doing this in an interactive program, that is, with REBOL/View.

    At a console prompt, I can do this:

    >> TESTNAME: %abc.def
    == %abc.def
    >> reverse next find reverse to-string TESTNAME "."
    == "abc"
    >>

    ...and all looks good.

    However, when I put the above idea into a screen, like this:

    REBOL [
    ]

    FILENAME: %abc.def

    view layout [
    across
    text "Original name:"
    text to-string FILENAME
    return
    text "Base file name:"
    text reverse next find reverse to-string FILENAME "."
    return
    button "Halt" [halt]
    ]

    ...the "Base file name" display shows fed.abc. Note that the "abc" is there, but preceded by the extension in a reversed form.

    I've been beating my head on this for several hours. Whatever I am doing wrong must be fairly simple; how complicated can ONE LINE of code be?

    Can anyone point me to my error or lack of understanding?

    Thank you.
  2. Graham

    Graham Developer Staff Member

    The function 'layout takes a block which contains a dialect ie. VID or visual interface dialect. It does not contain REBOL.

    You can evaluate any REBOL inside the block by enclosing in parentheses, and using compose

    eg
  3. MaxV

    MaxV Member

    Eh eh eh, try this:
    Code:
    FILENAME: %abc.def
    ORNAME: reverse next find reverse to-string FILENAME "."
    >> index? ORNAME
    == 5
    >> ORNAME: head ORNAME
    == "fed.abc"
    
    You copied all the string/series but you see only from the position of the series and on... The index is at position 5...

    Try:
    Code:
    ORNAME: rejoin [reverse next find reverse to-string FILENAME "."]
    

Share This Page