In-script command to copy all do files in the current directory to another folder in Stata

点点圈 提交于 2019-12-08 04:13:19

Working backwards: the current do-file is not a clearly defined concept. Do-files can be nested, so Stata could start with a.do which calls b.do which calls c.do .... So, what's the current do-file? All of them.

As you nearly say, you can get a list of files of a certain kind in the current directory by (e.g.)

local filelist : dir . files "*.do" 

Copying to bar just requires you to mention bar, although it seems you want to change the filename too:

foreach f of local filelist { 
    local F : subinstr local f ".do" "2.do", all  
    copy `f'  bar/`F' 
} 

Using a forward slash is prudent even under Windows. See the discussion here and its references.

Useful functions here are documented online and correspondingly within Stata:

 help extended fcn 
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!