Click here to Skip to main content
15,900,566 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Im trying to compare the file creation date with the one i have in my structure, however unlike a integer i cant use the operator > for this, have been searching for a reasonable explanation for a few hours now how to actually do this, but got none so far and thus im stuck.


C++
// Convert to string to use std::find function
			std::string temp(Current_File.cFileName);

			// Convert characters to lowercase
			std::transform(temp.begin(), temp.end(), temp.begin(), ::tolower);
			for (int i = 0; i < 100; i++)
			{
				// Maybe put this when the triggerword is actualy added, so it doesnt do it every freaking time it enters this loop
				std::transform(Triggers[i].Triggerword.begin(), Triggers[i].Triggerword.end(), Triggers[i].Triggerword.begin(), ::tolower);
				
				// If this triggerword is a channel and the string is not empty
				if (Triggers[i].Channel && Triggers[i].Triggerword != "")
				{
					if (temp.find(Triggers[i].Triggerword) != std::string::npos || Triggers[i].Triggerword == "*")
					{
						// Count positives for debugging
						found++;
						for (int c = 0; c < 100; c++)
						{
							if (Triggers[i].Triggerword == Files[c].Triggername || Files[c].Triggername == "")
							{
								Files[c].Triggername = Triggers[i].Triggerword;
								if (Current_File.ftCreationTime > Files[c].FileDate)
								{
									Files[c].FileDate = Current_File.ftCreationTime;
								}
								// We found what we needed, exit both loops and get the next file
								c = 100;
								i = 100;
							}
						}
					}
				}
			}


Files Filedate is FILETIME FileDate; in a structure.


So to round it up, my question here is, how do I check if the creationtime/date of the file is greater then the value in FileDate ?
(Ps. this is for windows if that matters)

Thanks in advance

What I have tried:

Mostly googling, since the documentation does not state what type FILETIME actualy realy is, i've checked the headerfile of it in vc++ but that does not give me any clarity of what that realy is.
Posted
Updated 29-Nov-18 23:47pm
Comments
Rick York 30-Nov-18 16:24pm    
"Mostly googling, since the documentation does not state what type FILETIME actualy realy is, i've checked the headerfile of it in vc++ but that does not give me any clarity of what that realy is."

I am not sure where this is coming from but is not at all true. You can right click the word FILETIME and select "Go To Definition" and it will show you what it really is.

Try to use CompareFileTime function | Microsoft Docs[^] :

C++
LONG CompareFileTime(
  const FILETIME *lpFileTime1,
  const FILETIME *lpFileTime2
);
 
Share this answer
 
Yes, you can use the normal relational operators on time values. You just need to ensure that both are in the same form. See https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/nf-fileapi-getfiletime[^].
 
Share this answer
 
It seems i did not pay attention.
Solution to my problem was :

Current_File.ftCreationTime.dwHighDateTime > Files[c].FileDate.dwHighDateTime

Thanks for the replies!
 
Share this answer
 
Comments
Rick York 30-Nov-18 10:56am    
If the dwHighDateTime fields are equal they can still differ in dwLowDateTime and if Current_File's was less then you would have an incorrect result.

It is better to convert to a (U)LARGE_INTEGER and compare the QuadPart values. I believe that is what the function in _duDE's solution does.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900