我一直在编写程序来打印正在访问的文件的名称以及访问文件的时间。基本上,我没有获取我输入的文件路径名,而是获取文件的所有子目录的名称。我强烈怀疑它与我在程序结束时使用的event->名称有关。我应该使用其他功能吗?
代码如下:
string filename;
printf("Please enter the file path name: ");
getline(cin, filename);
/*Create a List<string> for multiple files to be entered*/
list<string> stringlist;
list<string>::iterator it;
stringlist.push_back(filename);
it = stringlist.begin();
while(filename != "exit")
{
/*Check whether files exists. Prompt user to re-enter filename*/
while(FileExists(filename) == false )
{
printf("File %s does not exist. Try again.\n", filename.c_str());
printf("Please enter the file path name: ");
getline(cin, filename);
}
printf("Please enter the next file: ");
getline(cin, filename);
if(filename != "exit")
stringlist.push_back(filename);
}
int index = 0;
wd = 0;
length = read(fd, buffer, BUF_LEN);
while(i < length) {
struct inotify_event* event = (struct inotify_event * ) &buffer[i];
if(event->mask & IN_ACCESS)
{
log.WriteFile(event->name);
}
i+= EVENT_SIZE + event->len;
}