General discussion

  • Creator
    Topic
  • #2084275

    C++ Sample Code for non-empty Directory

    Locked

    by hueristic ·

    Need working sample code.

All Comments

  • Author
    Replies
    • #3782149

      C++ Sample Code for non-empty Directory

      by lastorck ·

      In reply to C++ Sample Code for non-empty Directory

      ok, but i didn’t try it. Hope it ll work properly. I use VC++5.0. Good luck!

      #include
      #include
      #include
      #include

      int MyDelDir(const string& path)
      {
      string _path(path + “\\*.*”);
      WIN32_FIND_DATA data;

      HANDLE hd = FindFirstFile(_path.c_str(), &data);
      if(hd != INVALID_HANDLE_VALUE)
      do
      {
      if(data.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY)
      {
      if(data.cFileName[0] != ‘.’) //not current & up
      MyDelDir(path + “\\” + data.cFileName);
      }
      else
      {
      if(!DeleteFile((path + “\\” + data.cFileName).c_str())
      break; //error!!!
      }
      }while(FindNextFile(hd, &data));

      if(GetLastError() != ERROR_NO_MORE_FILES)
      return 1; //error!!!

      if(!FindClose(hd))
      return 2; //error!!!

      if(!RemoveDirectory(path.c_str()))
      return 3; //error!!!

      return 0; //OK
      }

Viewing 0 reply threads