|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 ..
|
| }
|
|
|
| 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" { |
|
|
| local gt8=(length("``i''")>8)
|
| local gt8="| `gt8'"
|
| }
|
| if index("``i''"," ") `gt8' {
|
| tempfile temp
|
| _getfilename "`temp'"
|
| local tfilen "`r(filename)'"
|
|
|
| local tfileh=substr("`tfilen'",1,index("`tfilen'",".")-1)
|
| quietly {
|
| cd "`path'\"
|
|
|
|
|
| ! dir /x /a "``i''"* > "`temp'"
|
| tempname in
|
| file open `in' using `"`temp'"', r
|
| file read `in' line
|
| local dline ""
|
| local dir "<DIR>"
|
| while r(eof) == 0 {
|
|
|
| file read `in' line
|
| if `: list local(dir) in local(line) ' {
|
| local dline `"`line'"'
|
| }
|
| }
|
| local gotit = 0
|
| local shortname ""
|
| local n = 1
|
| while `gotit' == 0 {
|
| local shortname : word `n' of `dline'
|
| if `: list local(shortname) == local(dir) ' {
|
|
|
| local shortname : word `= `n' + 1' of `dline'
|
| local gotit = 1
|
| }
|
| local n = `n' + 1
|
| }
|
| }
|
| local sdir`i'=trim(substr(`"`shortname'"',1,10))
|
| }
|
| else {
|
| local sdir`i' "``i''"
|
| }
|
| if "``i''"!="\" {
|
| local path "`macval(path)'\\`sdir`i''"
|
| }
|
| }
|
| local i=`i'+1
|
| }
|
| quietly cd "`macval(cwd)'\\\"
|
| local shortdir="`path'"+"\"
|
| return local shortdir `shortdir'
|
| }
|
| else {
|
| di "{error}shortdir only works in Windoze."
|
| exit
|
| }
|
|
|
| end
|
|
|