如果在申报时间声明 [英] If Statement On Filetime

查看:113
本文介绍了如果在申报时间声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个if语句,如果文件小于或等于两秒钟,它就会执行任何操作.这是在文件时间.
已更新.

I have an if statement that does whatever if a file is two seconds old or less. This is in filetime.
Updated.

using namespace std;

typedef vector<win32_find_data> tFoundFilesVector; 
std::string LastWriteTime;

int getPassList(const char * filespec, tFoundFilesVector &foundFiles)
{ 
    WIN32_FIND_DATA findData; 
    HANDLE h; 
    int validResult=true; 
 
    int numFoundFiles = 0; 
    h = FindFirstFile((LPCSTR)filespec, &findData); 
    if (h == INVALID_HANDLE_VALUE) 
        return 0; 
 
    while (validResult) 
    { 
        numFoundFiles++; 
        foundFiles.push_back(findData); 
        validResult = FindNextFile(h, &findData); 
    } 
    FindClose(h);
	return numFoundFiles; 
} 


void PASS(tFoundFilesVector &fileList) 
{//Pass Open 
    unsigned _int64 fileTime, curTime, age; 
    tFoundFilesVector::iterator iter; 
    FILETIME ftNow; 
    CoFileTimeNow(&ftNow); 
        curTime = ((_int64) ftNow.dwHighDateTime << 32) + ftNow.dwLowDateTime; 
 
        for (iter=fileList.begin(); iter<filelist.end();>
		{//For Open 
        fileTime = ((_int64)iter->ftLastWriteTime.dwHighDateTime << 32) + iter->ftLastWriteTime.dwLowDateTime; 
 
        age = curTime - fileTime;
		
		if (age <= (_int64)20000000UL)// 2 Seconds
			{//if Age Open
			rename(string("c:\\Users\\DS\\Downloads\\").append(string(iter->cFileName)).c_str(), string("c:\\PASS\\").append(string(iter->cFileName)).c_str());
			}//If Age Close
		}//For Close 
}//Pass Close </win32_find_data>





然而;如果文件的时间为0秒,则不会执行任何操作.我是否需要更改if语句?任何帮助表示赞赏.谢谢.





However; it''s not doing whatever if the file is 0 Seconds old. Do I need to change the if statement? Any help is appreciated. Thank you.

推荐答案

好,如所转贴,我没有发现任何明显的错误.但是,如果您希望从以下答复之一中回答问题:
OK, as reposted, I don''t see anything obviously wrong. However, if you want an answer to the question from one of your replies:
语录:

如所写,它会基于以下文件运行代码:是2秒或更短的时间(包括0秒)?

As written does it run the code based on a file that is 2 seconds old or less, including 0 seconds?

,然后一定要使用调试器在各种语句上设置断点并找出自己.这里没有人会拿走所有这些代码并在自己的系统上运行,只是为了看看它是否有效.确定其是否有效的最佳人选是您.

PS,从数学上讲0秒是< = 2秒,因此您无需更改任何内容.

(已编辑)

哦,有一件事,从此(_int64)20000000UL中删除"UL". (__int64)20000000就足够了.

另外,为什么在int64声明/类型转换中只有一个"_"?我以为是__int64(两个下划线)

then by all means use the debugger to set breakpoints on various statements and find out yourself. Nobody here is going to take all that code and run it on their own systems just to see if it works. The best person to determine if it works is YOU.

PS, mathematically 0 seconds is <= 2 seconds so there''s nothing you should change.

(edited)

Oh, one thing, remove the "UL" from this (_int64)20000000UL. (__int64)20000000 is sufficient.

Also, why do you have a single "_" in the int64 declaration / typecast? I thought it was __int64 (two underscores)


值"20000000UL"不能完全是FILETIME,它实际上是一个64位值,而是表示为两个32位的结构价值观.如果您声明,则不需要类型大小写;您需要使用代表2秒的数值.您真正需要转换的是FILETIME__int64.试试:
The value "20000000UL" cannot be exactly FILETIME which is really a 64-bit value, but expressed as a structure of two 32-bit values. If your statement, you don''t need a type case; you need to use you numeric value representing 2 seconds. What you really need to convert is FILETIME to __int64. Try:
__int64 age = (__int64(filetime.dwHighDateTime)<<32) | __int64(filetime.dwLowDateTime);



—SA



—SA


这篇关于如果在申报时间声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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