Jump to content

Counting the number of files in a folder.


CadFrank

Recommended Posts

  • Replies 47
  • Created
  • Last Reply

Top Posters In This Topic

  • CadFrank

    23

  • Tharwat

    12

  • BlackBox

    5

  • hanhphuc

    4

(vl-load-com)

(defun c:FOO (/ *error* oShell oFolder path i)

 (defun *error* (msg)
   (if oShell
     (vlax-release-object oShell)
   )
   (cond ((not msg))                                                   ; Normal exit
         ((member msg '("Function cancelled" "quit / exit abort")))    ; <esc> or (quit)
         ((princ (strcat "\n** Error: " msg " ** ")))                  ; Fatal error, display it
   )
   (princ)
 )

 (if
   (and
     (setq oShell (vla-getinterfaceobject
                    (vlax-get-acad-object)
                    "Shell.Application"
                  )
     )
     (setq oFolder (vlax-invoke
                     oShell
                     'BrowseForFolder
                     (vla-get-hwnd acApp)
                     "Select folder to search:"
                     0
                     (+ 1 64 256)
                   )
     )
     (setq path (vlax-get-property
                  (vlax-get-property oFolder 'Self)
                  'Path
                )
     )
   )
    (progn
      (prompt (strcat "\nSelected folder: \"" path "\" "))
      (prompt
        (strcat
          "\n"
          (itoa (setq i (length (vl-directory-files path "*.*" 1))))
          (if (= 1 i)
            " file "
            " files "
          )
          "found."
        )
      )
    )
 )
 (*error* nil)
)

Link to comment
Share on other sites

Well thank Tharwat it almost what I need ill figure out the rest.

 

I changed

 (if (setq f (vl-directory-files (getvar 'dwgprefix) nil 1))
 (length f)
 )

 

Thing is since the file is opened it count the .dwl and .dwl2

 

But like it said ill figure it out

 

Cheers & Beer !

Link to comment
Share on other sites

Well thank Tharwat it almost what I need ill figure out the rest.

 

I changed

 (if (setq f (vl-directory-files (getvar 'dwgprefix) nil 1))
 (length f)
 )

 

Thing is since the file is opened it count the .dwl and .dwl2

 

But like it said ill figure it out

 

Cheers & Beer !

 

You have to set the Extension parameter of the vl-Directory-Files function accordingly... "*.dwg" as example.

Link to comment
Share on other sites

Well thank Tharwat it almost what I need ill figure out the rest.

 

I changed

 (if (setq f (vl-directory-files (getvar 'dwgprefix) nil 1))
 (length f)
 )

 

Thing is since the file is opened it count the .dwl and .dwl2

 

But like it said ill figure it out

 

Cheers & Beer !

 

have a play with this then :)

 

(if
 (and (setq
        f (vl-directory-files
            (getvar 'dwgprefix)
            nil
            1
          )
      )
      (setq l (vl-remove-if '(lambda (ex) (wcmatch ex "*.dwl,*.dwl2")) f))
 )
  (length l)
)

Link to comment
Share on other sites

have a play with this then :)

 

(if
 (and (setq
        f (vl-directory-files
            (getvar 'dwgprefix)
            nil
            1
          )
      )
      (setq l (vl-remove-if '(lambda (ex) (wcmatch ex "*.dwl,*.dwl2")) f))
 )
  (length l)
)

 

Is the OP attempting to quantify everything except *.dwl* files, or all files of one or more specific extensions?

Link to comment
Share on other sites

Is the OP attempting to quantify everything except *.dwl* files, or all files of one or more specific extensions?

 

I guess all files as it is clear from the title of the thread :)

Link to comment
Share on other sites

But I wanted to figured out the rest.

 

I can certainly appreciate that, however....

 

I am trying to get the .dwg files.

 

... ^^ This ^^ should have been included here, in order to avoid this:

 

 

 

I guess all files as it is clear from the title of the thread :)

 

 

 

 

Cheers

Link to comment
Share on other sites

Well I just read on the Vl-derectory-files. Now I feel bad it actually says what I wanted lol !

 

Shoulda dug more hehe would've found the answer in my book :)

Link to comment
Share on other sites

(if (setq f (vl-directory-files "C:\\Users\\Tharwat\\Desktop\\New Folder" nil 1))
 (length f)
 )

 

FWIW, the if statement is not required since (length nil) = 0

 

(length (vl-directory-files (getvar 'dwgprefix) "*.dwg" 1))

Link to comment
Share on other sites

FWIW, the if statement is not required since (length nil) = 0

 

 

I am always concern about the first statement before feeding or processing to conclusion and good to know that length function would exit safely if argument is equal to nil . :)

 

Thanks a lot .

Link to comment
Share on other sites

Ok! well i've been on this for a few more hours and can't figure it out!

 

Now If I want to make sure that in the file it counts files with a specific string only.

 

For exemple :

 

(setq
        f (vl-directory-files
            (getvar 'dwgprefix)
            "*.dwg"
            1
          )
      )

 

("1456546756.dwg" "2014-08-11 - LU-14094 - Plan de coffrage des culées - rev.00.dwg" "2014-08-11 - LU-14094-02 - Plan de coffrage des culées - rev.00.dwg")

 

Now using :

 

(setq l (vl-remove-if '(lambda (ex) (wcmatch ex "*LU-14094*")) f))

 

("1456546756.dwg")

 

Now I've tried alot and can't seem to figure out how to extract the other one.

 

Any one can Help plz!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...