Skip to content

Instantly share code, notes, and snippets.

@katahiromz
Created September 23, 2019 03:04
Show Gist options
  • Save katahiromz/63c00d6c670370d7602fcd991fdc0eba to your computer and use it in GitHub Desktop.
Save katahiromz/63c00d6c670370d7602fcd991fdc0eba to your computer and use it in GitHub Desktop.
15_548.cpp
#include <windows.h>
#include <shlobj.h>
#include <shlwapi.h>
#include <stdio.h>
#include <vector>
#pragma comment(lib, "shlwapi.lib")
std::vector<FILETIME> filetimes;
void DoRecurse(LPCWSTR dir)
{
WCHAR szPath[MAX_PATH];
lstrcpyW(szPath, dir);
PathAppendW(szPath, L"*");
WIN32_FIND_DATAW find;
HANDLE hFind = FindFirstFileW(szPath, &find);
if (hFind != INVALID_HANDLE_VALUE)
{
do
{
if (find.cFileName[0] == L'.')
{
continue;
}
if (find.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
WCHAR szPath2[MAX_PATH];
lstrcpyW(szPath2, dir);
PathAppendW(szPath2, find.cFileName);
DoRecurse(szPath2);
}
else
{
filetimes.push_back(find.ftLastWriteTime);
}
} while (FindNextFileW(hFind, &find));
}
FindClose(hFind);
}
int main(void)
{
WCHAR szPath[MAX_PATH];
SHGetSpecialFolderPathW(NULL, szPath, CSIDL_PERSONAL, FALSE);
DoRecurse(szPath);
FILETIME local;
SYSTEMTIME st;
DWORD seconds[7] = { 0 };
DWORD count[7] = { 0 };
for (size_t i = 0; i < filetimes.size(); ++i)
{
FileTimeToLocalFileTime(&filetimes[i], &local);
FileTimeToSystemTime(&local, &st);
seconds[st.wDayOfWeek] += (st.wHour * 60 + st.wMinute) * 60 + st.wSecond;
count[st.wDayOfWeek]++;
}
LPCSTR wd = "日月火水木金土";
for (int i = 0; i < 7; ++i)
{
printf("%.2s: ", &wd[i * 2]);
if (count[i])
{
DWORD average = seconds[i] / count[i];
printf("%02d:%02d:%02d\n", average / 60 / 60 % 60,
average / 60 % 60, average % 60);
}
else
{
puts("-");
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment