Skip to content

Instantly share code, notes, and snippets.

@srz-zumix
Created October 30, 2016 13:03
Show Gist options
  • Save srz-zumix/5354b690f935ca3ee7edd1d6935741a5 to your computer and use it in GitHub Desktop.
Save srz-zumix/5354b690f935ca3ee7edd1d6935741a5 to your computer and use it in GitHub Desktop.
#include <windows.h>
#include <tchar.h>
void FindFirstFileTest()
{
_tprintf(_T("FindFirstFile\n"));
TCHAR buf[3] = _T("c:");
for( TCHAR letter = _T('c'); letter <= _T('z'); letter += 1 )
{
WIN32_FIND_DATA fd;
buf[0] = letter;
HANDLE hFind = FindFirstFile(buf, &fd);
if( hFind == INVALID_HANDLE_VALUE )
{
_tprintf(_T("%s = INVALID\n"), buf);
}
else
{
_tprintf(_T("%s = %s\n"), buf, fd.cFileName);
FindClose(hFind);
}
}
}
void FindFirstFileExTest(FINDEX_INFO_LEVELS finfoLevelId)
{
_tprintf(_T("FindFirstFileEx\n"));
TCHAR buf[3] = _T("c:");
for( TCHAR letter = _T('c'); letter <= _T('z'); letter += 1 )
{
WIN32_FIND_DATA fd;
buf[0] = letter;
HANDLE hFind = FindFirstFileEx(buf, finfoLevelId, &fd, FindExSearchNameMatch, NULL, 0);
if( hFind == INVALID_HANDLE_VALUE )
{
_tprintf(_T("%s = INVALID\n"), buf);
}
else
{
_tprintf(_T("%s = %s\n"), buf, fd.cFileName);
FindClose(hFind);
}
}
}
void TestAll()
{
FindFirstFileTest();
//FindFirstFileExTest(FindExInfoStandard);
//FindFirstFileExTest(FindExInfoBasic);
}
int main()
{
TCHAR current_drive_letter = _T('C');
{
TCHAR cd[MAX_PATH];
GetCurrentDirectory(MAX_PATH, cd);
current_drive_letter = cd[0];
_tprintf(_T("Current Directory: %s\n"), cd);
}
TestAll();
{
TCHAR cd[MAX_PATH] = _T("C:\\");
cd[0] = current_drive_letter;
SetCurrentDirectory(cd);
GetCurrentDirectory(MAX_PATH, cd);
_tprintf(_T("Current Directory: %s\n"), cd);
}
TestAll();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment