CadFrank Posted August 11, 2014 Share Posted August 11, 2014 Hi, Is there a way to count a number of files in a folder using an autolisp coding. Thx! Quote Link to comment Share on other sites More sharing options...
Ender181 Posted August 11, 2014 Share Posted August 11, 2014 I'm assuming there's a reason you want something other than just right clicking on the folder and selecting properties? Quote Link to comment Share on other sites More sharing options...
Tharwat Posted August 11, 2014 Share Posted August 11, 2014 Just an example (if (setq f (vl-directory-files "C:\\Users\\Tharwat\\Desktop\\New Folder" nil 1)) (length f) ) Quote Link to comment Share on other sites More sharing options...
BlackBox Posted August 11, 2014 Share Posted August 11, 2014 (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) ) Quote Link to comment Share on other sites More sharing options...
CadFrank Posted August 11, 2014 Author Share Posted August 11, 2014 Well reason would be I'm trying to input a value in an attribut according to de number of drawing in the file. Quote Link to comment Share on other sites More sharing options...
CadFrank Posted August 11, 2014 Author Share Posted August 11, 2014 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 ! Quote Link to comment Share on other sites More sharing options...
BlackBox Posted August 11, 2014 Share Posted August 11, 2014 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. Quote Link to comment Share on other sites More sharing options...
Tharwat Posted August 11, 2014 Share Posted August 11, 2014 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) ) Quote Link to comment Share on other sites More sharing options...
BlackBox Posted August 11, 2014 Share Posted August 11, 2014 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? Quote Link to comment Share on other sites More sharing options...
CadFrank Posted August 11, 2014 Author Share Posted August 11, 2014 I am trying to get the .dwg files. But I wanted to figured out the rest. Thx ! Quote Link to comment Share on other sites More sharing options...
Tharwat Posted August 11, 2014 Share Posted August 11, 2014 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 Quote Link to comment Share on other sites More sharing options...
BlackBox Posted August 11, 2014 Share Posted August 11, 2014 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 Quote Link to comment Share on other sites More sharing options...
Tharwat Posted August 11, 2014 Share Posted August 11, 2014 I am trying to get the .dwg files. But I wanted to figured out the rest. Thx ! So give your self a favor by reading about the function vl-directory-files Quote Link to comment Share on other sites More sharing options...
CadFrank Posted August 11, 2014 Author Share Posted August 11, 2014 Well I was going to ! I ain't an guru yet Thx for the help ! Quote Link to comment Share on other sites More sharing options...
Tharwat Posted August 11, 2014 Share Posted August 11, 2014 Well I was going to ! I ain't an guru yet Thx for the help ! Not a problem , just ask if you stuck with anything Quote Link to comment Share on other sites More sharing options...
CadFrank Posted August 11, 2014 Author Share Posted August 11, 2014 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 Quote Link to comment Share on other sites More sharing options...
Lee Mac Posted August 11, 2014 Share Posted August 11, 2014 (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)) Quote Link to comment Share on other sites More sharing options...
Tharwat Posted August 12, 2014 Share Posted August 12, 2014 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 . Quote Link to comment Share on other sites More sharing options...
CadFrank Posted August 12, 2014 Author Share Posted August 12, 2014 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! Quote Link to comment Share on other sites More sharing options...
hanhphuc Posted August 12, 2014 Share Posted August 12, 2014 maybe? (setq l (vl-remove-if[color="red"]-not[/color] '(lambda (ex) (wcmatch ex "*LU-14094*")) f)) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.