-1

struggling to create a function to verify every minute if the file has been modified. I have tried a few things, just not getting anywhere. Haven't done any programming for over 10 years, and that could be a problem too. Can someone put me on a right track? Thank you.

note: the file is created by another program and I cannot change the output or location

int file_is_modified() {
   /*
   I have a file "C://SMSTEXT.txt"
time1 = // time last modified
time2 = //current last time modified
   if time1==time2
        return no
    else
        return yes
    }
    */


int main() 
{  
    using namespace std::this_thread; // sleep_for, sleep_until
    using namespace std::chrono; // nanoseconds, system_clock, seconds
    do {
        do {
            file_is_modified();
            sleep_for(seconds(60));
            sleep_until(system_clock::now() + seconds(1));
        } while (file_is_modified()) //yes

        send_email("SMSTEXT.txt"); 
        //this function is working, sending string from file as email
       //update time1
time1 = time2;
    } while (//till program is closed)
    
    return 0;
}

  • If what you actually want to do is get a notification when a file is modified see https://stackoverflow.com/questions/931093/how-do-i-make-my-program-watch-for-file-modification-in-c for the more efficient solution – Alan Birtles Jun 01 '22 at 06:53

0 Answers0