*! wdadd1.ado v0.0.1 Scott Long 2017-07-21
program define wdadd1
    version 13.0

    args project

if "`project'"=="" {
    di ""
    di "The command -wdadd1 <project>- creates the ado file wd<project>.ado"
    di "that will change your working directory to your current directory."
    di "The ado file is saved in PERSONAL; run -sysdir- for location."
    di ""
    di "For example,-wdadd1 groups- creates -wdproject.ado-."
    di "Entering -wdproject- will change your working directory."
    exit
}

    local PERSONAL "`c(sysdir_personal)'"
    local adoname `"wd`project'"'
    local adofile `"`PERSONAL'`adoname'.ado"'
    local currentpwd `"`c(pwd)'"'
    local date : di %tcCCYY-NN-DD clock(c(current_date),"DMY")

    tempname adohandle
    file open  `adohandle' using `"`adofile'"', text write replace
    file write `adohandle' _col(1) `"*! `date' $S_NAME"' _new
    file write `adohandle' _col(1) `"program define `adoname'"' _new
    file write `adohandle' _col(4) `"version 13"' _new
    file write `adohandle' _col(4) `"cd "`currentpwd'""' _new
    file write `adohandle' _col(1) `"end"' _new
    file write `adohandle' _col(1) `"exit"' _new
    file close `adohandle'

    display `"`adoname'.ado saved in `PERSONAL'"'

end
exit