0

I'm trying to write a method to monitor a directory for a file to be created. This file will have the extension .complete. If it is not there, I want to wait for it to appear. When it does appear, I want to find extract the name of the file before the extension, delete the .complete file, do some processing, and then go back to listening for a new .complete file.

Here's what I have so far. I think I just need help extracting the name of the file, assuming I did the wildcard's correctly.

while(1) {
    if (!boost::filesystem::exists("/var/test/*.complete")) {
        cout << ".complete file does not exist" << endl;
    }
    else {

        //extract name of .complete file minus extension
        //do my processing
        system("rm *.complete");
    }
}
user1984300
  • 101
  • 3
  • 15

2 Answers2

0

I'm not used to boost, but in a few easy step you can get what you want

Step 1 : Read the directory (readdir or equivalent)

Step 2 : You'll get all files included in the directory as a const char *

Step 3 : Get std::string instead of const char *

Step 4 : fileName.find(".complete")

you get it :)

drumz
  • 65
  • 7
0

I figured it out

I used the get_all function from this answer below and added that to my program How to get list of files with a specific extension in a given folder

Community
  • 1
  • 1
user1984300
  • 101
  • 3
  • 15