代码改变世界

windows api 每日一练(1)目录操作

2009-11-17 09:36  Clingingboy  阅读(1450)  评论(0编辑  收藏  举报


1.创建目录

BOOL WINAPI CreateDirectory(
  __in_opt  LPCTSTR lpPathName,
  __in      LPSECURITY_ATTRIBUTES lpSecurityAttributes
);


2.删除目录

BOOL WINAPI RemoveDirectory(
  __in  LPCTSTR lpPathName
);


3.获取当前目录

DWORD WINAPI GetCurrentDirectory(
  __in   DWORD nBufferLength,
  __out  LPTSTR lpBuffer
);


4.设置当前目录

BOOL WINAPI SetCurrentDirectory(
  __in  LPCTSTR lpPathName
);


Test

#include <windows.h>
#include <stdio.h>
int main()
{
  std::wstring strDir(L"d:\\test\\testDir");
  CreateDirectory(strDir.c_str(),NULL);
  TCHAR szCurrentDirectory[MAX_PATH];
  DWORD length= GetCurrentDirectory(MAX_PATH,szCurrentDirectory);
  SetCurrentDirectory(strDir.c_str());
  GetCurrentDirectory(MAX_PATH,szCurrentDirectory);
  RemoveDirectory(strDir.c_str());
}