strip file name

Discussion in 'AutoCAD' started by Kiwi Russ, Dec 24, 2004.

  1. Kiwi Russ

    Kiwi Russ Guest

    If I have a list such as :

    ("myfile1.dwg" "myfile2.dwg" "myfile3.dwg" etc .....)

    how would I strip the .dwg from all the elements, so that the list would
    look something like:

    ("myfile1" "myfile2" "myfile3" etc .....)

    thanks Russ
     
    Kiwi Russ, Dec 24, 2004
    #1
  2. Kiwi Russ

    Rodney Estep Guest

    (foreach n mylist (setq newlist (append newlist (substr n 1 (- (strlen n)
    4)))))
    (setq mylist newlist newlist nil)


    Did not test but this is how to do it assuming of course that length of the
    extension is the same.
    Another approach that would work is stepping thru each letter of the string
    until you find the period then crop it off there.




    Rodney
     
    Rodney Estep, Dec 24, 2004
    #2
  3. Kiwi Russ

    Ken Krupa Guest

    (mapcar 'vl-filename-base mylist)

    Ken Krupa
     
    Ken Krupa, Dec 24, 2004
    #3
  4. Kiwi Russ

    Rob Taylor Guest

    Russ

    Ken Krupa reply
    (mapcar 'vl-filename-base mylist) is a good one

    it also works for all file types
    (setq MyList '("myfile1.lsp" "myfile2.lsp" "myfile3.lsp" "myfile42.lsp"))
    (mapcar 'vl-filename-base MyList)

    result :
    ("myfile1" "myfile2" "myfile3" "myfile42")

    so it's can replace some code in that MakefasM routine!
    Damn it, I'm going to have to learn more visual lisp!!

    Cheers
    Rob
     
    Rob Taylor, Dec 24, 2004
    #4
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.