Visual LISP, AutoLISP and General Customization

Reply
Mentor
The_Caddie
Posts: 208
Registered: ‎06-08-2010
Message 1 of 6 (348 Views)
Accepted Solution

Loop file names in command prompt

348 Views, 5 Replies
12-06-2012 04:57 AM

Hi,

 

I’m not so good with loops so I was wondering if anyone could help.

 

I have a parent directory with x-amount of folders contained inside. I say X-amount because I would like to keep adding or deleting folders as time progresses. I want the folders contained within this parent directory do be read into a lisp variable and then be printed to the command prompt till every folder is displayed by name, then the loop may stop.

 

Could somebody help with this?

Distinguished Contributor
phanaem
Posts: 149
Registered: ‎02-06-2007
Message 2 of 6 (339 Views)

Re: Loop file names in command prompt

12-06-2012 05:26 AM in reply to: The_Caddie

Try this

;prompt directory structure
;usage:
;  - dir = a directory to search
;  - flg = a flag. If True, look in subdirectories
; (prompt_dir "D:\\Temp" nil)
; (prompt_dir "D:\\Temp" T)
; Stefan M. 06.12.12 (defun prompt_dir (dir flg) (foreach sub (vl-remove "." (vl-remove ".." (vl-directory-files dir nil -1))) (princ (strcat "\n" dir "\\" sub)) (if flg (prompt_dir (strcat dir "\\" sub) flg)) ) (princ) )

 

Mentor
The_Caddie
Posts: 208
Registered: ‎06-08-2010
Message 3 of 6 (334 Views)

oo _    EEH?

12-06-2012 05:37 AM in reply to: phanaem

oo

 

EEH?

*Expert Elite*
hmsilva
Posts: 2,639
Registered: ‎12-17-2004
Message 4 of 6 (307 Views)

Re: Loop file names in command prompt

12-06-2012 07:42 AM in reply to: The_Caddie

The_Caddie wrote:
...I want the folders contained within this parent directory do be read into a lisp variable
and then be printed to the command prompt till every folder is displayed by name, then the loop may stop...

 

if I understood correctly try:

 

; Peter Tobey
(defun get-subdirs ( path )
(vl-load-com)
(apply (quote append)
(cons (list path)
(mapcar '(lambda (x) (get-subdirs (strcat path x "\\")))
(cddr (vl-directory-files path nil -1)))))
)

; test
(defun c:test(/ dir dir_lst)
(setq dir "C:\\test\\test\\"); your dir path
(if (setq dir_lst (get-subdirs dir))
   (foreach n dir_lst (prompt (strcat "\n" n "\n")))
  )
  )

 

Hope that helps,

 

Henrique

*Expert Elite*
pbejse
Posts: 2,406
Registered: ‎11-24-2009
Message 5 of 6 (268 Views)

Re: Loop file names in command prompt

12-07-2012 01:19 AM in reply to: phanaem

phanaem wrote:

Try this....


I was planning to write a similar recursion code using "Scripting.FileSystemObject" but its not near as fast as the one you posted.

 

Good show phanaem :smileyhappy:

 

 

Distinguished Contributor
phanaem
Posts: 149
Registered: ‎02-06-2007
Message 6 of 6 (248 Views)

Re: Loop file names in command prompt

12-07-2012 08:17 AM in reply to: pbejse

pbejse wrote:

I was planning to write a similar recursion code using "Scripting.FileSystemObject" but its not near as fast as the one you posted.

 

Good show phanaem :smileyhappy:


Very kind of you, pBe.Thanks a lot.
I'm still waiting The_Caddie to tell me if and what is wrong with my lisp...

 

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community