*! v0.8.0 2017-09-11 Scott Long  - workingdir.pkg

// drop or restore cdproject commands

capture program drop dropcd
program define dropcd
    version 13.0
    syntax namelist [ , hold REStore]

    if "`hold'"=="" & "`restore'"=="" local delete delete

    if "`restore'"=="restore" local suf "hold"
    else local suf "ado"

    //  list of names to process

    * if all, use any that start with cd in PERSONAL
    if "`namelist'"=="_all" {
        local cdfiles : dir "`c(sysdir_personal)'" files "cd*.`suf'"
    }
    * if single file
    else {
        local n12 = substr("`namelist'",1,2) // add cd if missing
        if "`n12'"!="cd" local namelist "cd`namelist'"
        local cdfiles "`namelist'.`suf'"
    }
    * remove suffix
    local cdfiles : subinstr local cdfiles ".`suf'" "", all

    //  delete or rename to hold

    if "`restore'"!="restore" {
        foreach file in `cdfiles' {
            * if not delete, make a copy then later delete
            if "`hold'"=="hold" {
                * copied file later deleed
                qui copy `"`c(sysdir_personal)'`file'.ado"' ///
                     `"`c(sysdir_personal)'`file'.hold"' , replace
                di as result "`file'.ado" as text " renamed " ///
                   as result "`file'.hold"
            }
            else di as result "`file'.ado" as text " deleted"
            * delete file
            rm `"`c(sysdir_personal)'`file'.ado"'
            * remove command from memory
            capture program drop `file'
        }
    }

    //  restore *.hold files to *.ado files

    else {
        foreach file in `cdfiles' {
            copy `"`c(sysdir_personal)'`file'.hold"' ///
                 `"`c(sysdir_personal)'`file'.ado"'
            if _rc==0 | _rc==111 { // copy successful
                rm `"`c(sysdir_personal)'`file'.hold"'
                di as result "`file'.hold" as text " renamed " ///
                   as result "`file'.ado"
            }
            else {
                di as result "`file'.hold" as text " not found"
            }
        } // file loop
    }

end
exit
* cddrop.ado v0.4.0 Scott Long 2017-08-02
* cddrop.ado v0.4.1 Scott Long 2017-08-02
* cddrop.ado v0.5.0 Scott Long 2017-08-04
* cddrop.ado v0.6.0 Scott Long 2017-08-13
* dropcd.ado v0.7.0 Scott Long 2017-09-07