Get free disk space

hello forum

i need my app to monitor the available disk space.

i know i can use

  
std::system("df -H");   

and it prints all the info i want in to the console. but i need to pass this info in to a variable and parse out the capacity info.

int var = std::system(“df”); does only return zero.

any ideas?
thx.

it’s always nice to find the answer to my question by myself.

  
  
  
void testApp::setup(){  
  
        string myInfo = myExec("df -H /Volumes");  
	cout<<"begin "<<myInfo<<" end"<<endl;  
  
	int pos = myInfo.find("%");  
  
	string myCapacityStr = myInfo.substr(pos-3,pos-1);  
	int myCapacityInt = ofToInt(myCapacityStr);  
		  
	cout<<"myCapacityStr "<<myCapacityStr<<endl;  
	cout<<"myCapacityInt "<<myCapacityInt<<endl;  
}  
  
  
string testApp::myExec(char* cmd) {  
	FILE* pipe = popen(cmd, "r");  
	if (!pipe) return "ERROR";  
	char buffer[128];  
	std::string result = "";  
	while(!feof(pipe)) {  
		if(fgets(buffer, 128, pipe) != NULL)  
			result += buffer;  
	}  
	pclose(pipe);  
	return result;  
}  
  
  

1 Like

and like this to get info about a video file

string myInfo = myExec("/usr/local/bin/ffprobe -i /Users/stephan/Desktop/sentence_pooling.mov -show_format -v quiet | sed -n \'s/duration=//p\'");
cout<<"begin "<<myInfo<<" end"<<endl;
1 Like

Very helpful thank you!
Did you try those codes on different platforms?

nope, only OS X