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

//  Program     : _cllct_getFileNameAndPath.ado
//  Author      :  Joseph D. Wolfe
//  Description : get file name and path to file if it exists
//  Requirements: >=Stata 10 (currently untested on previous versions)

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

//  #2
//  Parse path and set sreturns

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 ""
}

//  #3
//  end _getFileNameAndPath


end
exit