list files in directory

Discussion in 'AutoCAD' started by jclaidler, May 12, 2004.

  1. jclaidler

    jclaidler Guest

    With lisp, how can I get a list of all drawing files in a given directory, but eliminate the extension from list.

    For example, if directory has drawing1.dwg and drawing2.dwg, the list will just show drawing1 and drawing 2.

    Thanks for any help.
     
    jclaidler, May 12, 2004
    #1
  2. (mapcar
    'vl-filename-base
    (vl-directory-files
    (getvar "dwgprefix"); or your path here
    "*.dwg"
    1
    )
    )
     
    Jason Piercey, May 12, 2004
    #2
  3. jclaidler

    BillZ Guest

    (vl-directory-files "G:/" nil -1)


    Bill
     
    BillZ, May 12, 2004
    #3
  4. jclaidler

    BillZ Guest

    Sorry,
    Hit the post button accidentally.

    (mapcar '(lambda (x)(vl-filename-base x))(vl-directory-files "G:/" nil
    1))
     
    BillZ, May 12, 2004
    #4
  5. jclaidler

    BillZ Guest

    Jason,

    Much bettter method.

    I should have seen that but I must have Lambda imbedded still from vanilla lisp.

    :)

    Bill
     
    BillZ, May 12, 2004
    #5
  6. jclaidler

    jclaidler Guest

    Here is what I have, but I get no result.

    (if (=
    (setq ss (ssget "X" (list (cons 0 "INSERT"))))
    (mapcar 'vl-filename-base (vl-directory-files "c:/USA" "*.dwg" 1 )))
    (command "erase" ss "")
    )
     
    jclaidler, May 12, 2004
    #6
  7. I'm a little lost with what you are trying to do.

    Do you want to get a list of drawing files in a
    given directory, and then for each drawing
    found if that block name exists in the current
    drawing file, erase all insertions?
     
    Jason Piercey, May 12, 2004
    #7
  8. jclaidler

    jclaidler Guest

    yes
     
    jclaidler, May 12, 2004
    #8
  9. jclaidler

    jclaidler Guest

    Now I have this... but returns nil.

    (vlax-for blocks (vla-get-blocks (vla-get-activedocument (vlax-get-acad-object)))(setq result (cons (vla-get-name blocks) result)))

    (setq lt1 (reverse result))

    (foreach n lt1

    (if (setq filename (findfile (strcat "L:/COMPASS 2000 Server/DUERR_AutoCADTitleBlocks/USA" n ".dwg")))

    (progn
    (setq blockname (vl-filename-base filename))
    (setq ss (ssget "X" (list (cons 2 blockname))))
    (command "erase" ss "")

    )
    )
    )
     
    jclaidler, May 12, 2004
    #9
  10. Completely untested and written on the fly.

    (foreach item <list of file names>
    (setq ss (ssget "x" (list '(0 . "INSERT") (cons 2 item))))
    (if ss
    (progn
    (setq i 0)
    (repeat (sslength ss)
    (vla-delete (vlax-ename->vla-object (ssname ss i)))
    (setq i (1+ i))
    )
    )
    (princ (strcat "\n" item " not found"))
    )
    )
     
    Jason Piercey, May 12, 2004
    #10
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.