*! version 1.0.0  14jul2005  <website> 14jul2005
program bmatatalk
	version 9

	local dir boston05matatalk
	local http http://www.stata.com/users/wgould/`dir'

	syntax [, UPDATE]

	capture confirm file `"`c(sysdir_personal)'`dir'/talk.smcl"'
	if !_rc & "`update'" == "" {
		di as error "`c(sysdir_personal)'`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:/`dir'"

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

	foreach file of local tfiles {
		gettoken name filenms : filenms

		copy `"`file'"' `"`c(sysdir_personal)'`dir'/`name'"' ,  ///
				`replace'
	}

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