Click here to Skip to main content
15,906,329 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Starting .exe... Pin
macmac381-Jul-03 1:56
macmac381-Jul-03 1:56 
GeneralRe: Starting .exe... Pin
Joan M1-Jul-03 3:21
professionalJoan M1-Jul-03 3:21 
GeneralRe: Starting .exe... Pin
macmac381-Jul-03 4:40
macmac381-Jul-03 4:40 
GeneralRe: Starting .exe... Pin
basementman1-Jul-03 5:52
basementman1-Jul-03 5:52 
GeneralDirectx and the VC++ .NET environment Pin
JamesLaing30-Jun-03 23:17
JamesLaing30-Jun-03 23:17 
GeneralDelete All folder and its contents Pin
rohit.dhamija30-Jun-03 22:54
rohit.dhamija30-Jun-03 22:54 
GeneralRe: Delete All folder and its contents Pin
Ryan Binns30-Jun-03 23:06
Ryan Binns30-Jun-03 23:06 
GeneralRe: Delete All folder and its contents Pin
Anonymous30-Jun-03 23:08
Anonymous30-Jun-03 23:08 
try this:
#include <string><br />
#include <iostream><br />
<br />
#include <conio.h><br />
<br />
<br />
int DeleteDirectory(const std::string &refcstrRootDirectory)<br />
{<br />
  std::string     strFilePath;           // Path of file<br />
  std::string     strPattern;            // Pattern<br />
  HANDLE          hFile;                 // Handle to file<br />
  WIN32_FIND_DATA FileInformation;       // File information<br />
<br />
<br />
  strPattern = refcstrRootDirectory + "\*.*";<br />
  hFile = ::FindFirstFile(strPattern.c_str(), &FileInformation);<br />
  if(hFile != INVALID_HANDLE_VALUE)<br />
  {<br />
    do<br />
    {<br />
      if(FileInformation.cFileName[0] != '.')<br />
      {<br />
        strFilePath.erase();<br />
        strFilePath = refcstrRootDirectory + "\" + FileInformation.cFileName;<br />
<br />
        if(FileInformation.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)<br />
        {<br />
          // Delete subdirectory<br />
          int iRC = DeleteDirectory(strFilePath);<br />
          if(iRC)<br />
            return iRC;<br />
        }<br />
        else<br />
        {<br />
          // Set file attributes<br />
          if(::SetFileAttributes(strFilePath.c_str(),<br />
                                 FILE_ATTRIBUTE_NORMAL) == FALSE)<br />
            return ::GetLastError();<br />
<br />
          // Delete file<br />
          if(:eleteFile(strFilePath.c_str()) == FALSE)<br />
            return ::GetLastError();<br />
        }<br />
      }<br />
    } while(::FindNextFile(hFile, &FileInformation) == TRUE);<br />
<br />
    // Close handle<br />
    ::FindClose(hFile);<br />
<br />
    DWORD dwError = ::GetLastError();<br />
    if(dwError != ERROR_NO_MORE_FILES)<br />
      return dwError;<br />
    else<br />
    {<br />
      // Set directory attributes<br />
      if(::SetFileAttributes(refcstrRootDirectory.c_str(),<br />
                             FILE_ATTRIBUTE_NORMAL) == FALSE)<br />
        return ::GetLastError();<br />
<br />
      // Delete directory<br />
      if(::RemoveDirectory(refcstrRootDirectory.c_str()) == FALSE)<br />
        return ::GetLastError();<br />
    }<br />
  }<br />
<br />
  return 0;<br />
}<br />
<br />
<br />
int main()<br />
{<br />
  std::string strDirectoryToDelete = "c:mydir";<br />
<br />
  // Delete 'c:mydir' and its subdirectories<br />
  int iRC = DeleteDirectory(strDirectoryToDelete);<br />
  if(iRC)<br />
  {<br />
    std::cout << "Error " << iRC << endl;<br />
    return -1;<br />
  }<br />
<br />
  // Wait for keystroke<br />
  _getch();<br />
<br />
  return 0;<br />
}

GeneralRe: Delete All folder and its contents Pin
Rickard Andersson2030-Jun-03 23:13
Rickard Andersson2030-Jun-03 23:13 
GeneralRe: Delete All folder and its contents Pin
Ryan Binns1-Jul-03 0:07
Ryan Binns1-Jul-03 0:07 
GeneralNot exactly C++ -> Setup Project Pin
Brian Delahunty30-Jun-03 22:36
Brian Delahunty30-Jun-03 22:36 
GeneralRe: Not exactly C++ -&gt; Setup Project Pin
Rage30-Jun-03 23:20
professionalRage30-Jun-03 23:20 
GeneralRe: Not exactly C++ -&gt; Setup Project Pin
Brian Delahunty30-Jun-03 23:37
Brian Delahunty30-Jun-03 23:37 
GeneralRe: Not exactly C++ -&gt; Setup Project Pin
Brian Delahunty1-Jul-03 0:24
Brian Delahunty1-Jul-03 0:24 
GeneralOpenSSL Pin
Ravi Jadhav30-Jun-03 22:28
Ravi Jadhav30-Jun-03 22:28 
GeneralComboBox Pin
bigmirror30-Jun-03 22:11
bigmirror30-Jun-03 22:11 
GeneralRe: ComboBox Pin
Ryan Binns30-Jun-03 22:19
Ryan Binns30-Jun-03 22:19 
GeneralRe: ComboBox Pin
bigmirror30-Jun-03 22:28
bigmirror30-Jun-03 22:28 
GeneralRe: ComboBox Pin
Ryan Binns30-Jun-03 22:41
Ryan Binns30-Jun-03 22:41 
GeneralAbout &quot;&amp;&quot; Pin
FlyingDancer30-Jun-03 22:00
FlyingDancer30-Jun-03 22:00 
GeneralRe: About &quot;&amp;&quot; Pin
FlyingDancer30-Jun-03 22:03
FlyingDancer30-Jun-03 22:03 
GeneralRe: About &quot;&amp;&quot; Pin
Toni7830-Jun-03 22:07
Toni7830-Jun-03 22:07 
GeneralRe: About &quot;&amp;&quot; Pin
Cedric Moonen30-Jun-03 22:11
Cedric Moonen30-Jun-03 22:11 
GeneralRe: About &quot;&amp;&quot; Pin
FlyingDancer30-Jun-03 22:26
FlyingDancer30-Jun-03 22:26 
GeneralRe: About &quot;&amp;&quot; Pin
PJ Arends30-Jun-03 22:53
professionalPJ Arends30-Jun-03 22:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.