*! usesasdel Version 2.0 dan_blanchette@unc.edu 16Mar2009 *! the carolina population center, unc-ch ** Center for Entrepreneurship and Innovation Duke University's Fuqua School of Business ** shortdir Version 2.0 dan_blanchette@unc.edu 17Jan2008 ** research computing, unc-ch * - added check that if forward slashes used as dir separators * then that is handled by converting them to back slashes * - uses Nick Cox's way of loading a text file line by line * into a local macro instead of reading it in as a dataset ** shortdir Version 1.1 dan_blanchette@unc.edu 28Oct2004 * - added test that directory actually exists ** shortdir Version 1.0 dan_blanchette@unc.edu 09Oct2003 ** the carolina population center, unc-ch program define shortdir, rclass version 8 syntax using/ [, SHort ] confirmdir "`using'" if _rc !=0 { di `"{error}The directory "`using'" does not exist."' exit _rc } if "`c(os)'"=="Windows" { preserve local cwd "`c(pwd)'`macval(\\\)'" if "`using'"=="." { local using "`macval(cwd)'" } if "`using'"=="`cwd'" { quietly cd .. } // check if forward slashes used and replace them if so local subtest : subinstr local using `"/"' `""' , count(local cnt) if `cnt' != 0 { local using : subinstr local using "/" "\" , all } tokenize "`using'" , parse("\") local i=1 while "``i''" !="" { if `i'==1 { local path "`1'" } else { if "`short'"=="short" { /* create macro that conditionally checks * for longer than 8 letter directory names */ local gt8=(length("``i''")>8) local gt8="| `gt8'" } if index("``i''"," ") `gt8' { /* if sub dir name has space in name or maybe longer than 8 */ tempfile temp _getfilename "`temp'" local tfilen "`r(filename)'" local tfileh=substr("`tfilen'",1,index("`tfilen'",".")-1) /* create file handle */ quietly { cd "`path'\" // options /x and /a create a short directory listing // so `temp' is a very small, short file ! dir /x /a "``i''"* > "`temp'" tempname in file open `in' using `"`temp'"', r file read `in' line local dline "" local dir "