*! version 1.0.0  05oct2005  <website> 05oct2005
program mata2005
	version 9

	local talkdir mata2005
	local dir `"`c(sysdir_personal)'`talkdir'"'
	local http http://www.stata.com/users/wgould/boston05matatalk

	syntax [, UPDATE]

	capture confirm file `"`dir'/talk.smcl"'
	if !_rc & "`update'" == "" {
		di as error "`dir' already exists"
		di as text "{p 4 4 0}" ///
			"specify {cmd:update} option if " ///
			"you wish to update the existing " ///
			"version of the talk{p_end}"
		exit 198
	}

	if ("`update'" != "") local replace replace

				// read file names from users/wgould
				// copying contents to temporary staging
				// files.

	tempname fh

	di "Copying talk materials from www.stata.com"
	local end 0
	file open `fh' using `http'/filelist, read text
	file read `fh' filenm
	while r(eof) == 0 & !`end' {
		if (`"`filenm'"' == `"<end>"') {
			local end 1
			continue, break
		}
		tempfile tf
		di as res `"	copying `filenm'"'
		copy `http'/`filenm' `"`tf'"'
		local filenms `filenms' `filenm'
		local tfiles `"`tfiles' `"`tf'"'"'

		file read `fh' filenm
	}
	file close `fh'

	if !`end' {
		di as error "{p 0 4 4}" ///
			"problem copying full set of files " ///
			"from www.stata.com, no changes made"
		exit 612
	}

	local end 0
	file open `fh' using `http'/eispack/filelist, read text
	file read `fh' filenm
	while r(eof) == 0 & !`end' {
		if (`"`filenm'"' == `"<end>"') {
			local end 1
			continue, break
		}
		tempfile tf
		di as res `"	copying `filenm'"'
		copy `http'/eispack/`filenm' `"`tf'"'
		local filenms `filenms' eispack/`filenm'
		local tfiles `"`tfiles' `"`tf'"'"'

		file read `fh' filenm
	}
	file close `fh'

	if !`end' {
		di as error "{p 0 4 4}" ///
			"problem copying full set of files " ///
			"from www.stata.com, no changes made"
		exit 612
	}

				// all files sucessfully copied, copy from
				// temps to final destination.
	di ""
	di "Moving talk materials to  PERSONAL:/`talkdir'"

	capture confirm file `"`dir'/talk.smcl"'
	if _rc {
		mkdir `"`dir'"'
		mkdir `"`dir'/eispack"'
	}

	foreach file of local tfiles {
		gettoken name filenms : filenms

		copy `"`file'"' `"`dir'/`name'"' ,  ///
				`replace'
	}

	di ""
	di "Type {stata help mata2005} to access talk materials"
end