*! cddrop.ado v0.5.0 Scott Long 2017-08-04
*! cddrop.ado v0.4.1 Scott Long 2017-08-02
*! cddrop.ado v0.4.0 Scott Long 2017-08-02
*! TODO: if first letters are not cd*.ado, try adding cd
capture program drop cddrop
program define cddrop
    version 13.0
    syntax namelist [ , delete REStore]

    * list of names to process
    if "`namelist'"=="_all" {
        if "`restore'"=="" local suf "ado"
        if "`restore'"=="restore" local suf "dropped"
        local cdfiles : dir "`c(sysdir_personal)'" files "cd*.`suf'"
    }
    else {
        local cdfiles `namelist'
**TODO        local cdado "cd`namelist'"
**TODO        * allow name to be cdproject or just project
**TODO        local cdfiles : subinstr local cdado "cdcd" "cd", all
    }
    * remove suffix
    local cdfiles : subinstr local cdfiles ".`suf'" "", all

    * delete or rename ado files
    if "`restore'"=="" {
        foreach file in `cdfiles' {
            * if not delete, make a copy then later delete
            if "`delete'"!="delete" {
                copy `"`c(sysdir_personal)'`file'.ado"' ///
                     `"`c(sysdir_personal)'`file'.dropped"' , replace
            di as result "`file'.ado" as text " renamed " ///
               as result "`file'.dropped"
            }
            else di as result "`file'.ado" as text " deleted"
            * delete even if rename
            rm `"`c(sysdir_personal)'`file'.ado"' // delete
        } // file loop
    } // not restore

    * restore cd*.dropped files to cd*.ado files
    else {
        foreach file in `cdfiles' {
            copy `"`c(sysdir_personal)'`file'.dropped"' ///
                 `"`c(sysdir_personal)'`file'.ado"'
        } // file loop
    }
end
exit

cddrop aut

cddrop cdaut

cddrop _all

cddrop aut, delete

cddrop cdaut, delete

cddrop _all, delete


cddrop aut, restore

cddrop cdaut, restore

cddrop _all, restore