eblog 发表于 2010-2-6 16:25 
arlionn 发表于 2010-2-6 16:14 
我觉得最好能编写一个“读写”文件的程序,把stata输入项中的参数传递给 DOS 命令集,然后输出新定义的 DOS 批处理文件,命名为 *.bat。整个过程相当于在修改 DOS 批处理文件。
接下来,只需执行 shell *.bat 文件即可。
这种处理方法的好处是,只需很少的修改就可以在stata中使用现有的 DOS 批处理文件了。
基本原则:尽可能少地改动 DOS 批处理文件,stata只发挥参数传递功能。
嗯,如果能这样就太好了
粗略程序如下,TO(string) 选项尚未处理,留给 eblog 吧。
*------------------------------------------------
cap program drop testdos
program define testdos
version 10
syntax , Find(string) TYpe(string) Dosfile(string) [TO(string)]
* error: only one word in `find'
* error: `type' .doc or just doc
tempname mydos
file open `mydos' using "`dosfile'.txt", write replace
file write `mydos' "@echo off&setlocal enabledelayedexpansion" _n
file write `mydos' "for %%a in (*`find'*.`type') do ( " _n
file write `mydos' "copy %%a d:\*.txt" _n // 此处尚未设定文件路径
file write `mydos' ")"
file close `mydos'
shell rename `dosfile'.txt `dosfile'.bat
shell `dosfile'.bat
end
exit
*------------------------------------------------
测试方式:
set trace on
testdos, find(j) type(txt) dos(s)