Folder List

Discussion in 'AutoCAD' started by Jasehuss, Aug 17, 2004.

  1. Jasehuss

    Jasehuss Guest

    Can anyone help me with a bit of code I'm struggling with,

    I need to return a list of directories that recurses down the folder structure (ie returns all subfolders) from a given starting point until it can go no further.

    Can anyone point me in the right direction to do this?

    Regards
    Jason
     
    Jasehuss, Aug 17, 2004
    #1
  2. Jasehuss

    zeha Guest

    Jason,

    Maybe this

    (vl-directory-files (getvar"dwgprefix") nil -1)

    Cheers

    Harrie
     
    zeha, Aug 17, 2004
    #2
  3. Jasehuss

    ECCAD Guest

    Jason,
    This function needs the DOS Lib loaded, and will 'find'
    a particular filename. You could modify it to cons a list
    of the folders if needbe.

    (defun find_me ( fname / dir ddir dir_lst ddir_lst )
    (setq dir_lst (dos_subdir "C:")); get sub-directory list
    (foreach dir dir_lst
    (setq ddir_lst (dos_subdir (strcat "C:/" dir)))
    (if ddir_lst
    (progn
    (foreach ddir ddir_lst
    (setq cf nil)
    (setq cf (dos_search fname (strcat "C:/" dir "/" ddir)))
    (if cf
    (progn
    (princ (strcat "\n" cf))
    (setq return (cons cf return))
    ); progn
    ); if
    (if Return
    (setq return (reverse return))
    ); if
    ); foreach
    ); progn
    ); if
    ); foreach
    ); defun
    ;; Variable Return = 'list' of all folders containing matched filename
    ;;


    Bob
     
    ECCAD, Aug 17, 2004
    #3
  4. Jasehuss

    ECCAD Guest

    zhea,
    That's too simple :)
     
    ECCAD, Aug 17, 2004
    #4
  5. Jasehuss

    Jasehuss Guest

    Thanks Harry,

    Already looked at that tho',

    It doesn't quite do what I need it to, as it only returns the first level of sub dirs.

    cheers
    J
     
    Jasehuss, Aug 17, 2004
    #5
  6. Jasehuss

    Jasehuss Guest

    Cheers Bob,

    I'm going to have a look at your code to see if i can adapt it.

    Thank-you
     
    Jasehuss, Aug 17, 2004
    #6
  7. Jasehuss

    zeha Guest

    Jason,

    This is a modified function created by Luis Esquivel

    With many subdirs it a litlebit slow

    I hope this is what you looking for

    (defun search_sub_folders (path)
    (vl-load-com)
    (setq path (if (wcmatch path "*\\") path (strcat path "\\")))
    (vl-remove nil (mapcar '(lambda (sub)
    (if(not(wcmatch sub "`.*"))
    (cons (strcat path sub)
    (apply 'append (search_sub_folders (strcat path sub))))))
    (vl-directory-files path nil -1))))


    Cheers,

    Harrie
     
    zeha, Aug 18, 2004
    #7
  8. Jasehuss

    Jürg Menzi Guest

    Hi Jason

    This code returns folders recursive or not recursive with or without
    file names:
    Code:
    ;
    ; == Function MeGetFolders
    ; Scans from current folder (recursive) for folders (and files).
    ; Arguments [Type]:
    ;   Fol = Root folder [STR]
    ;   Pat = File name pattern
    ;         - Not False: eg. *.*, *.dwg [STR]
    ;         - False:     Folders only [BOOLEAN]
    ;   Rec = Recursive flag [BOOLEAN]
    ;         - True:  scan folders recursive
    ;         - False: scan first folder level
    ; Return [Type]:
    ;   > If pattern argument False:
    ;     '("Pth1" "Pth2"...) [LIST]
    ;   > If pattern argument not False:
    ;     '(("Pth1" '("Fil1" "Fil2"...)) ("Pth2" '(...))...) [LIST]
    ; Notes:
    ;   - If no files found in a folder, the file list returns a '("").
    ;   - Deep folder structure slow down the function.
    ;
    (defun MeGetFolders (Fol Pat Rec / FolLst TmpFol)
    (setq TmpFol (if (wcmatch Fol "*\\") (substr Fol 1 (1- (strlen Fol))) Fol)
    FolLst (cons TmpFol (apply 'append (MeGetFoldersRec TmpFol Rec)))
    )
    (if Pat
    (mapcar
    '(lambda (l)
    (cons l (cond ((vl-directory-files l Pat 1)) ('(""))))
    ) FolLst
    )
    FolLst
    )
    )
    ;
    ; == Function MeGetFoldersRec
    ; Recursive function for MeGetFolders.
    ; Arguments [Type]:
    ;   Fol = Folder [STR]
    ;   Rec = Recursive flag [BOOLEAN]
    ;         - True:  scan folders recursive
    ;         - False: scan first folder level
    ; Return [Type]:
    ;   > Folder list '((Pth1) (Pth2)) [LIST]
    ; Notes:
    ;   Return value contain nil atoms.
    ;
    (defun MeGetFoldersRec (Fol Rec / TmpFol)
    (mapcar
    '(lambda (l)
    (if (not (wcmatch l "`.*"))
    (cons
    (setq TmpFol (strcat Fol "\\" l))
    (if Rec (apply 'append (MeGetFoldersRec TmpFol Rec)))
    )
    )
    ) (vl-directory-files Fol nil -1)
    )
    )
    
    Cheers
     
    Jürg Menzi, Aug 18, 2004
    #8
  9. Jasehuss

    John Uhden Guest

    From 3-07-2004

    ;; Function to create a tree-structured list of folders
    ;; given the parent folder as a Path.
    ;; Note that using a path of "" or "." or "\\" will exclude
    ;; the drive letter. McNeel's DOSLIB has a DOS_FULLPATH function
    ;; that can return such folders with drive designations.
    ;; (c) John F. Uhden, Cadlantic
    (defun @Folders (Path / Folders @Dirs)
    (defun @Dirs (Path / Dir Dirs)
    (and
    (= (type Path) 'STR)
    (or
    (/= (type DOS_FULLPATH) 'EXRXSUBR)
    (setq Path (DOS_FULLPATH Path))
    )
    (if (wcmatch Path ",*/,*\\")
    (setq Dir Path)
    (setq Dir (strcat Path "\\"))
    )
    (setq Dirs (vl-directory-files Dir "*.*" -1))
    (setq Folders (cons Path Folders))
    (setq Dirs (vl-remove-if '(lambda (x)(vl-position x '("." ".."))) Dirs))
    (mapcar '@Dirs (mapcar '(lambda (x)(strcat Dir x)) Dirs))
    )
    )
    (@Dirs Path)
    (reverse Folders)
    )



    (ie returns all subfolders) from a given starting point until it can go no
    further.
     
    John Uhden, Aug 19, 2004
    #9
  10. Jasehuss

    Jasehuss Guest

    Thanks for all the posts here guys, I'm sure there will be something I can use here

    Very much appreciated

    Regards
    Jason
     
    Jasehuss, Aug 19, 2004
    #10
  11. Jasehuss

    Jasehuss Guest

    Just the Job, Thankyou very much.
     
    Jasehuss, Aug 19, 2004
    #11
  12. Jasehuss

    Jürg Menzi Guest

    Welcome...:cool:

    Cheers
     
    Jürg Menzi, Aug 19, 2004
    #12
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.