I'm trying to create a folder named by todays date (on Ubuntu) and then check if it's empty or not.
The empty-or-not check will be done several times daily.
#include <cstdlib>
#include <unistd.h>
#include <stdio.h>
#include <iostream>
#include <typeinfo>
#include <chrono>
#include <time.h>
#include <iomanip>
using namespace std;
int main() {
//Pull out system date and create a folder named by system date
auto const now = std::chrono::system_clock::now();
auto const in_time_t = std::chrono::system_clock::to_time_t(now);
std::stringstream ss;
ss << std::put_time(std::localtime(&in_time_t), "%d_%m_%Y");
// Creating todays date folder with entry folder
string str_2=std::string("mkdir -p " + string(ss.str()) + "/entry");
const char *com2=str_2.c_str();
system(com2);
//check if directory is empty or not
int check;
char is_empty[100];
FILE * output;
output = popen("ls " + ss.str() + "/entry | wc -l","r") ;
fgets (is_empty, 100, output); //write to the char
pclose (output);
check = atoi(is_empty);
if (check == 0) {
cout << "The folder is empty" << endl;
}
}
I'm getting this error when compiling this code:
error: no match for ‘operator+’ (operand types are ‘const char [4]’
and ‘std::stringstream {aka std::__cxx11::basic_stringstream<char>}’)
output = popen("ls " +ss+ "/entry | wc -l","r") ;