All pastes #23869 Raw Edit

Miscellany

public text v1 · immutable
#23869 ·published 2005-09-25 18:23 UTC
rendered paste body
void change_dir(const char* path, ofstream& file, bool print)
{
	char cwd[256];
	if((string)path == "")
	{
		if(print)
			file<<getcwd(cwd,sizeof(cwd))<<endl;
		else
			cout<<getcwd(cwd,sizeof(cwd))<<endl;
	}
	else if(chdir(path) != 0)
	{
		if(print)
			file<<"ERROR: myshell: "<<path<<" does not exist"<<endl;
		else
			cout<<"ERROR: myshell: "<<path<<" does not exist"<<endl;

	}
		
	string temp = (string)getcwd(cwd,sizeof(cwd));
	path = temp.c_str();
	setenv("PWD",path,1);
}