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?
Solved! Go to Solution.
Solved by hmsilva. Go to Solution.
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) )
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
@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...