Please help save my sanity...
-
I am writing a small program in C++ without MFC(call me a glutton for punishment, but I want to avoid the hassle of the dependancy). The premise of the program is that it will delete all of the files in a given directory if the file is older than a given number of days. 99% of the application works fine, except the code below: FILETIME ft; ULONGLONG qwResult; ft = getTimeInFiletime(); //ULONGLONG localAge = (ULONGLONG)age; // Copy the time into a quadword. qwResult = (((ULONGLONG) ft.dwHighDateTime) << 32) + ft.dwLowDateTime; // Subtract x days. ULONGLONG lngDaysToSubtract; lngDaysToSubtract = age* _DAY; qwResult -= lngDaysToSubtract; // Copy the result back into the FILETIME structure. ft.dwLowDateTime = (DWORD) (qwResult & 0xFFFFFFFF ); ft.dwHighDateTime = (DWORD) (qwResult >> 32 ); This code is creating a FILETIME structure that will contain the "cuttof date", for example if someone calls the program with a parameter of 30 days, it will create a FILETIME structure containing the date of 30 days ago. The problem here is this line: lngDaysToSubtract = age* _DAY; "age" is an int parameter passed into this function. If I replace this variable with a hard-coded parameter, say 30, this code works fine. But it fails if I use the function parameter. If I throw in a "printf("Age is: %s\n",age);", it shows that the value is what I expect it to be. I have been banging my head on this problem all morning. If anyone can help me solve it, I would be extremely grateful!! Thanks
-
I am writing a small program in C++ without MFC(call me a glutton for punishment, but I want to avoid the hassle of the dependancy). The premise of the program is that it will delete all of the files in a given directory if the file is older than a given number of days. 99% of the application works fine, except the code below: FILETIME ft; ULONGLONG qwResult; ft = getTimeInFiletime(); //ULONGLONG localAge = (ULONGLONG)age; // Copy the time into a quadword. qwResult = (((ULONGLONG) ft.dwHighDateTime) << 32) + ft.dwLowDateTime; // Subtract x days. ULONGLONG lngDaysToSubtract; lngDaysToSubtract = age* _DAY; qwResult -= lngDaysToSubtract; // Copy the result back into the FILETIME structure. ft.dwLowDateTime = (DWORD) (qwResult & 0xFFFFFFFF ); ft.dwHighDateTime = (DWORD) (qwResult >> 32 ); This code is creating a FILETIME structure that will contain the "cuttof date", for example if someone calls the program with a parameter of 30 days, it will create a FILETIME structure containing the date of 30 days ago. The problem here is this line: lngDaysToSubtract = age* _DAY; "age" is an int parameter passed into this function. If I replace this variable with a hard-coded parameter, say 30, this code works fine. But it fails if I use the function parameter. If I throw in a "printf("Age is: %s\n",age);", it shows that the value is what I expect it to be. I have been banging my head on this problem all morning. If anyone can help me solve it, I would be extremely grateful!! Thanks
Not the right place to post a code-related topic. Maybe 'age' is not the problem, but _DAY is. Try: int iDay(_DAY); lngDaysToSubtract = age * iDay; -- Alex Marbus www.marbus.net