*! wdlist.ado v0.1.1 Scott Long 2017-07-22
*! wdlist.ado v0.1.0 Scott Long 2017-07-22
program define wdlist
    version 13.0

    syntax [ , Details]

    // get names of wd*.ado file in PERASONALs

    local wdadofiles : dir "`c(sysdir_personal)'" files "wd*.ado"

//  list wd*.ado files in PERAONAL

    di `"Commands to change the working directory"' _new

//  simple list

    if "`details'"=="" {

        foreach file in `wdadofiles' {
            local cmd : subinstr local file ".ado" "", all
            di _col(4) `"`cmd'"'
        }
        di _new "Run -wdlist, details- for detailed information"

    }

//  details

    else {

        local currentpwd `"`c(pwd)'"'

        foreach file in `wdadofiles' {
            local cmd : subinstr local file ".ado" "", all
            capture qui `cmd'
            local error = _rc

            if _rc!=0 {
                di _col(4) `"`cmd'"'
                di _col(8) `"working directory: directory does not exist"' _new
            }
            else {
                di _col(4) `"`cmd'"'
                di _col(8) `"working directory: `c(pwd)'"'
                di _col(8) `"global S_data:     $S_data"' _new
            }
        }
        qui cd `"`currentpwd'"' // return to starting working directory
    }

end
exit