*! cdlist.ado v0.1.0 Scott Long 2017-07-23
program define cdlist
    version 13.0

    syntax [ , Details]

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

    local cdmakefiles : dir "`c(sysdir_personal)'" files "cd*.ado"

//  list cd*.ado files in PERAONAL

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

//  simple list

    if "`details'"=="" {

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

    }

//  details

    else {

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

        foreach file in `cdmakefiles' {
            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