*! version 0.0.1  03/01/11 12:31 PM

//  Author      : Joseph D. Wolfe
//  Description : get file name and path to file if it exists
//  Requirements: Stata 10.1 (currently untested on other versions)

program  _getFileNameAndPath, sclass
	syntax, fileinfo(string)
	version 10

if regexm(`"`fileinfo'"', "[\]|[/]")  {
	local more `"`fileinfo'"'
	local stop = 1

	while `stop' != 0 {
		if regexm(`"`more'"', "[\]") {
			gettoken hold more : more, parse("\")
			local PathToFile `"`macval(PathToFile)'`hold'"'
			local trash : subinstr local more "\" "", all count(local stop)
		}

		if regexm(`"`more'"', "[/]") {
			gettoken hold more : more, parse("/")
			local PathToFile "`macval(PathToFile)'`hold'"
			local trash : subinstr local more "/" "", all count(local stop)
		}
	}
	sreturn local file_name  `"`more'"'
	sreturn local PathToFile `"`PathToFile'"'
}

else {
	sreturn local file_name `"`fileinfo'"'
	sreturn local PathToFile ""
}

end // _getFileNameAndPath



exit

*Version History
* version 0.0.1  03/01/11 12:31 PM
	* created for use with graphout and graphsto