Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Loop file names in command prompt

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
The_Caddie
764 Views, 5 Replies

Loop file names in command prompt

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?

5 REPLIES 5
Message 2 of 6
phanaem
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) )

 

Message 3 of 6
The_Caddie
in reply to: phanaem

oo

 

EEH?

Message 4 of 6
hmsilva
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

EESignature

Message 5 of 6
pbejse
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 🙂

 

 

Message 6 of 6
phanaem
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 🙂


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...

 

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost