C++文件目录的创建,复制等操作

来源:互联网 发布:agv导航算法 编辑:程序博客网 时间:2024/05/17 23:53

1) First all the functions are in <direct.h> file, you can find it in VS directory.
 _mkdir(char * path); // create
 _chdir(char * path); 
 _rmdir(char * path); // it should be empty
 _getcwd(...);

.....

2) A way to empty the directory
EmptyDirectory(char* folderPath)
{
 char fileFound[256];
 WIN32_FIND_DATA info;
 HANDLE hp;
 sprintf(fileFound, "%s%c*.*", folderPath, SLASH);
 hp = FindFirstFile(fileFound, &info);
 do
 {
  if (!((strcmp(info.cFileName, ".")==0)||
     (strcmp(info.cFileName, "..")==0)))
  {
    if((info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)==
          FILE_ATTRIBUTE_DIRECTORY)
    {
     string subFolder = folderPath;
 #ifndef MAINWIN
     subFolder.append("\\");
 #else
     subFolder.append("/");
 #endif
     subFolder.append(info.cFileName);
     EmptyDirectory((char*)subFolder.c_str());
     RemoveDirectory(subFolder.c_str());
    }
    else
    {
     sprintf(fileFound,"%s%c%s", folderPath, SLASH, info.cFileName);
     BOOL retVal = DeleteFile(fileFound);
    }
  }

 }while(FindNextFile(hp, &info));
 FindClose(hp);
}

 

原创粉丝点击