Piece

[C] GetCurrentDirectory GetWindowsDirectory GetSystemDirectory

More Code 2018. 6. 25. 23:07


#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#include <tchar.h>

int _tmain(INT32 argc, LPTSTR argv[])
{
// MAX_PATH : The maximum character length of a path.
TCHAR currentDirectory[MAX_PATH];
TCHAR windowsDirectory[MAX_PATH];
TCHAR systemDirectory[MAX_PATH];

// GetCurrentDirectory GetWindowsDirectory GetSystemDirectory
// If the function fails, the return value is zero.

DWORD result1 = GetCurrentDirectory(MAX_PATH, currentDirectory);
if (result1 != 0)
_tprintf(_T("Current Directory \t %s \n"), currentDirectory);

DWORD result2 = GetWindowsDirectory(windowsDirectory, MAX_PATH);
if (result2 != 0)
_tprintf(_T("Windows Directory \t %s \n"), windowsDirectory);

DWORD result3 = GetSystemDirectory(systemDirectory, MAX_PATH);
if (result3 != 0)
_tprintf(_T("System Directory \t %s \n"), systemDirectory);

return EXIT_SUCCESS;
}

/* Output
Current Directory C:\Source\VisualStudio\System1\System1
Windows Directory C:\Windows
System Directory C:\Windows\system32
*/