C ++如何比较(大于)ftcreationtime与windows? [英] C++ how do I compare (greater then) ftcreationtime with windows ?

查看:132
本文介绍了C ++如何比较(大于)ftcreationtime与windows?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将文件创建日期与我的结构中的文件创建日期进行比较,但不像整数我不能使用运算符>为此,一直在寻找一个合理的解释几个小时现在如何实际做到这一点,但到目前为止没有,因此我卡住了。





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.


// 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.





所以要把它四舍五入,我的问题在这里是,如何检查文件的创建时间/日期是否大于FileDate中的值?

(如果重要的话,这是针对Windows的)



提前致谢



我尝试过:



主要使用Google搜索,因为文档没有说明FILETIME实际上是什么类型,我已经在vc ++中检查了它的头文件,但这并没有让我明白这是什么。



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.

推荐答案

尝试使用 CompareFileTime函数| Microsoft Docs [ ^ ]:



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

LONG CompareFileTime(
  const FILETIME *lpFileTime1,
  const FILETIME *lpFileTime2
);


是的,您可以在时间值上使用常规关系运算符。您只需要确保两者的形式相同。请参阅 https://docs.microsoft.com/en-us/windows / desktop / api / fileapi / nf-fileapi-getfiletime [ ^ ]。
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[^].


好像我没注意。

解决我的问题是:



Current_File.ftCreationTime.dwHighDateTime>文件[c] .FileDate.dwHighDateTime



感谢您的回复!
It seems i did not pay attention.
Solution to my problem was :

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

Thanks for the replies!


这篇关于C ++如何比较(大于)ftcreationtime与windows?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆