Viewing contents of file '../idllib/contrib/fanning/alldir.pro'
Function AllDir, target

; This function returns the names of all the directories
; rooted at the "target" directory. The function is specific
; for the Windows operating system. The return names are
; given with respect to the target name.

On_Error, 1

    ; Default directory is current directory.

IF N_Params() EQ 0 THEN BEGIN
   CD, Current=target
   target = target + '\'
ENDIF

    ; Check to see if target argument is a string.

variableType = Size(target, /Type)
IF variableType NE 7 THEN $
    Message, 'Argument must be STRING type.'

    ; Move to target directory.

CD, target, Current=thisDirectory

    ; Find the files in the target directory.

theseFiles = Findfile('*', Count=count)
IF count EQ 0 THEN RETURN, ''

    ; Find the directories in the file list. Directories
    ; end with a "\" character.

endCharPos = StrLen(theseFiles) - 1
FOR j=0,count-1 DO BEGIN
    IF theseFiles[j] NE '.\' AND theseFiles[j] NE '..\' THEN BEGIN
        lastChar = StrMid(theseFiles[j], endCharPos[j], 1)
        IF lastChar EQ '\' THEN BEGIN
            IF N_Elements(theseDirs) EQ 0 THEN $
                theseDirs = [theseFiles[j], AllDir(theseFiles[j])] ELSE $
                theseDirs = [theseDirs, theseFiles[j], AllDir(theseFiles[j])]
        ENDIF
    ENDIF ELSE theseDirs = ''
ENDFOR

    ; Add the target directory to each directory name.

theseDirs = target + theseDirs

    ; Move back to the starting directory.

CD, thisDirectory

    ; Remove null strings and non-unique values.

theseDirs = theseDirs[Where(theseDirs NE target) > 0]
theseDirs = theseDirs[Uniq(theseDirs)]

    ; Return the list.

RETURN, theseDirs
END