본문 바로가기
Borland

현재 디렉토리 구하기

by leo21c 2008. 3. 4.
현재 디렉토리 구하기 프로그래밍

http://blog.naver.com/area1001/10015201487

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

#define BUFSIZE MAX_PATH

int _tmain(int argc, TCHAR **argv, TCHAR **envp)
{
TCHAR Buffer[BUFSIZE];
TCHAR changePath[] = "C:\\Documents and Settings\\deaa\\바탕 화면\\Directory\\ChangedCurrentDir";
DWORD dwRet;

// if(argc != 2)
// {
// _tprintf(TEXT("Usage: Test <dir>\n"));
// return 0;
// }

dwRet = GetCurrentDirectory(BUFSIZE, Buffer);

if( dwRet == 0 )
{
_tprintf(TEXT("GetCurrentDirectory failed (%d)\n"), \
GetLastError());
return 0;
}
if(dwRet > BUFSIZE)
{
_tprintf(TEXT("GetCurrentDirectory failed (buffer too small; \
need %d chars)\n"), dwRet);
return 0;
}

printf("현재 디렉토리\n");
_tprintf(TEXT("Get current directory to %s\n"), Buffer);

if( !SetCurrentDirectory(changePath) )
{
_tprintf(TEXT("SetCurrentDirectory failed (%d)\n"), \
GetLastError());
return 0;
}
printf("바꿔진 현재 디렉토리\n");
//_tprintf(TEXT("Set current directory to %s\n"), argv[1]);
_tprintf(TEXT("Set current directory to %s\n"), changePath);

//if( !SetCurrentDirectory(Buffer) )
//{

// _tprintf(TEXT("SetCurrentDirectory failed (%d)\n"), \
// GetLastError());
// return 0;
// }
// _tprintf(TEXT("Restored previous directory (%s).\n"), Buffer);


dwRet = GetCurrentDirectory(BUFSIZE, Buffer);
printf("현재 디렉토리\n");
_tprintf(TEXT("Get current directory to %s\n"), Buffer);
return 1;
}