*做了一个纯stata框架下的程序,相当于把dos命令译成stata命令:
*`anything'中前者是原文件名(含目录,可含通配符),后者是到达目录,两者要用双引号。
cap pr drop scopy
pr scopy
syntax anything [,Replace]
if strpos(`"`anything'"',`"""')==0{
n di as error "Directories or files should be enclosed by double quotes"
exit
}
token `"`anything'"',p(`"""')
if "`3'"!=""{
n di as error "At most two directories/files can be input"
exit
}
if "`2'"=="" loc 2=c(pwd)
_getfilename "`1'"
loc from=substr("`1'",1,length("`1'")-length("`r(filename)'")-1)
if "`from'"=="" loc from=c(pwd)
loc files: dir "`from'" file "`r(filename)'"
loc from="`from'"+"/"
if `"`files'"'!=""{
loc t=0
foreach x of loc files {
if "`replace'"!="" copy "`from'`x'" "`2'",replace
else {
cap copy "`from'`x'" "`2'"
if _rc {
n di as error "`x' already existed in `2'"
continue
}
}
loc t=`t'+1
}
n di "`t' copied"
}
else n di as error "No proper file existed in `from'"
end


雷达卡



京公网安备 11010802022788号







