<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Ordner Loeschen]]></title><description><![CDATA[<p>Hi,<br />
ich habe ein Prog was einen Ordner loescht, jetzt moechte ich aber das er nicht den Ordner selbst loescht sondern nur die Dateien die in ihm sind.</p>
<p>Hoffe ihr koennt mir helfen.</p>
<pre><code class="language-cpp">#include &lt;string&gt;
#include &lt;iostream&gt;

#include &lt;windows.h&gt;
#include &lt;conio.h&gt;

using namespace std;

int DeleteDirectory(const std::string &amp;refcstrRootDirectory,
                    bool              bDeleteSubdirectories = true)
{
  bool            bSubdirectory = false;       // Flag, indicating whether
                                               // subdirectories have been found
  HANDLE          hFile;                       // Handle to directory
  string     strFilePath;                 // Filepath
  string     strPattern;                  // Pattern
  WIN32_FIND_DATA FileInformation;             // File information

  strPattern = refcstrRootDirectory + &quot;\\*.*&quot;;
  hFile = ::FindFirstFile(strPattern.c_str(), &amp;FileInformation);
  if(hFile != INVALID_HANDLE_VALUE)
  {
    do
    {
      if(FileInformation.cFileName[0] != '.')
      {
        strFilePath.erase();
        strFilePath = refcstrRootDirectory + &quot;\\&quot; + FileInformation.cFileName;

        if(FileInformation.dwFileAttributes &amp; FILE_ATTRIBUTE_DIRECTORY)
        {
          if(bDeleteSubdirectories)
          {
            // Delete subdirectory
            int iRC = DeleteDirectory(strFilePath, bDeleteSubdirectories);
            if(iRC)
              return iRC;
          }
          else
            bSubdirectory = true;
        }
        else
        {
          // Set file attributes
          if(::SetFileAttributes(strFilePath.c_str(),
                                 FILE_ATTRIBUTE_NORMAL) == FALSE)
            return ::GetLastError();

          // Delete file
          if(::DeleteFile(strFilePath.c_str()) == FALSE)
            return ::GetLastError();
        }
      }
    } while(::FindNextFile(hFile, &amp;FileInformation) == TRUE);

    // Close handle
    ::FindClose(hFile);

    DWORD dwError = ::GetLastError();
    if(dwError != ERROR_NO_MORE_FILES)
      return dwError;
    else
    {
      if(!bSubdirectory)
      {
        // Set directory attributes
        if(::SetFileAttributes(refcstrRootDirectory.c_str(),
                               FILE_ATTRIBUTE_NORMAL) == FALSE)
          return ::GetLastError();

        // Delete directory
        if(::RemoveDirectory(refcstrRootDirectory.c_str()) == FALSE)
          return ::GetLastError();
      }
    }
  }

  return 0;
}

int main()
{
  int iRC = 0;
  string strDirectoryToDelete = &quot;c:\\Dokumente und Einstellungen\\Coda\\Desktop\\Matrix_D\\&quot;;

  // Delete 'c:\mydir' without deleting the subdirectories
  iRC = DeleteDirectory(strDirectoryToDelete, false);
  if(iRC)
  {
    return -1;
  }

  // Delete 'c:\mydir' and its subdirectories
  iRC = DeleteDirectory(strDirectoryToDelete);
  if(iRC)
  {
    return -1;
  }

  return 0;
}
</code></pre>
<p>MfG<br />
Coda</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/174587/ordner-loeschen</link><generator>RSS for Node</generator><lastBuildDate>Sun, 12 Jul 2026 14:27:10 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/174587.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 28 Feb 2007 20:04:04 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Ordner Loeschen on Wed, 28 Feb 2007 20:04:04 GMT]]></title><description><![CDATA[<p>Hi,<br />
ich habe ein Prog was einen Ordner loescht, jetzt moechte ich aber das er nicht den Ordner selbst loescht sondern nur die Dateien die in ihm sind.</p>
<p>Hoffe ihr koennt mir helfen.</p>
<pre><code class="language-cpp">#include &lt;string&gt;
#include &lt;iostream&gt;

#include &lt;windows.h&gt;
#include &lt;conio.h&gt;

using namespace std;

int DeleteDirectory(const std::string &amp;refcstrRootDirectory,
                    bool              bDeleteSubdirectories = true)
{
  bool            bSubdirectory = false;       // Flag, indicating whether
                                               // subdirectories have been found
  HANDLE          hFile;                       // Handle to directory
  string     strFilePath;                 // Filepath
  string     strPattern;                  // Pattern
  WIN32_FIND_DATA FileInformation;             // File information

  strPattern = refcstrRootDirectory + &quot;\\*.*&quot;;
  hFile = ::FindFirstFile(strPattern.c_str(), &amp;FileInformation);
  if(hFile != INVALID_HANDLE_VALUE)
  {
    do
    {
      if(FileInformation.cFileName[0] != '.')
      {
        strFilePath.erase();
        strFilePath = refcstrRootDirectory + &quot;\\&quot; + FileInformation.cFileName;

        if(FileInformation.dwFileAttributes &amp; FILE_ATTRIBUTE_DIRECTORY)
        {
          if(bDeleteSubdirectories)
          {
            // Delete subdirectory
            int iRC = DeleteDirectory(strFilePath, bDeleteSubdirectories);
            if(iRC)
              return iRC;
          }
          else
            bSubdirectory = true;
        }
        else
        {
          // Set file attributes
          if(::SetFileAttributes(strFilePath.c_str(),
                                 FILE_ATTRIBUTE_NORMAL) == FALSE)
            return ::GetLastError();

          // Delete file
          if(::DeleteFile(strFilePath.c_str()) == FALSE)
            return ::GetLastError();
        }
      }
    } while(::FindNextFile(hFile, &amp;FileInformation) == TRUE);

    // Close handle
    ::FindClose(hFile);

    DWORD dwError = ::GetLastError();
    if(dwError != ERROR_NO_MORE_FILES)
      return dwError;
    else
    {
      if(!bSubdirectory)
      {
        // Set directory attributes
        if(::SetFileAttributes(refcstrRootDirectory.c_str(),
                               FILE_ATTRIBUTE_NORMAL) == FALSE)
          return ::GetLastError();

        // Delete directory
        if(::RemoveDirectory(refcstrRootDirectory.c_str()) == FALSE)
          return ::GetLastError();
      }
    }
  }

  return 0;
}

int main()
{
  int iRC = 0;
  string strDirectoryToDelete = &quot;c:\\Dokumente und Einstellungen\\Coda\\Desktop\\Matrix_D\\&quot;;

  // Delete 'c:\mydir' without deleting the subdirectories
  iRC = DeleteDirectory(strDirectoryToDelete, false);
  if(iRC)
  {
    return -1;
  }

  // Delete 'c:\mydir' and its subdirectories
  iRC = DeleteDirectory(strDirectoryToDelete);
  if(iRC)
  {
    return -1;
  }

  return 0;
}
</code></pre>
<p>MfG<br />
Coda</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1237053</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1237053</guid><dc:creator><![CDATA[Coda*linux.PrayLoad]]></dc:creator><pubDate>Wed, 28 Feb 2007 20:04:04 GMT</pubDate></item><item><title><![CDATA[Reply to Ordner Loeschen on Mon, 05 Mar 2007 14:05:46 GMT]]></title><description><![CDATA[<p>Dieser Thread wurde von Moderator/in <a href="http://www.c-plusplus.net/forum/profile-var-mode-is-viewprofile-and-u-is-403.html" rel="nofollow">HumeSikkins</a> aus dem Forum <a href="http://www.c-plusplus.net/forum/viewforum-var-f-is-15.html" rel="nofollow">C++</a> in das Forum <a href="http://www.c-plusplus.net/forum/viewforum-var-f-is-4.html" rel="nofollow">WinAPI</a> verschoben.</p>
<p>Im Zweifelsfall bitte auch folgende Hinweise beachten:<br />
<a href="http://www.c-plusplus.net/forum/viewtopic-var-t-is-39405.html" rel="nofollow">C/C++ Forum :: FAQ - Sonstiges :: Wohin mit meiner Frage?</a></p>
<p><em>Dieses Posting wurde automatisch erzeugt.</em></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1239562</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1239562</guid><dc:creator><![CDATA[C++ Forumbot]]></dc:creator><pubDate>Mon, 05 Mar 2007 14:05:46 GMT</pubDate></item><item><title><![CDATA[Reply to Ordner Loeschen on Mon, 05 Mar 2007 14:38:42 GMT]]></title><description><![CDATA[<p>Coda@linux.PrayLoad schrieb:</p>
<blockquote>
<p>[...] jetzt moechte ich aber das er nicht den Ordner selbst loescht sondern nur die Dateien die in ihm sind.</p>
</blockquote>
<p>Dann musst Du diese Dateien wieder enumerieren (FindFirstFile, etc.) und anschließend auf jede einzelne <em>DeleteFile</em> anwenden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1239588</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1239588</guid><dc:creator><![CDATA[CodeFinder]]></dc:creator><pubDate>Mon, 05 Mar 2007 14:38:42 GMT</pubDate></item><item><title><![CDATA[Reply to Ordner Loeschen on Mon, 05 Mar 2007 14:46:47 GMT]]></title><description><![CDATA[<p>Wenn die Unterordnerstruktur erhalten werden soll, dann darf</p>
<pre><code class="language-cpp">if(!bSubDirectory)
</code></pre>
<p>nicht wahr werden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1239603</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1239603</guid><dc:creator><![CDATA[keksekekse]]></dc:creator><pubDate>Mon, 05 Mar 2007 14:46:47 GMT</pubDate></item><item><title><![CDATA[Reply to Ordner Loeschen on Mon, 05 Mar 2007 15:14:59 GMT]]></title><description><![CDATA[<p>amsonsten - ordner loeschen und dann neu erstellen lassen #gg</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1239631</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1239631</guid><dc:creator><![CDATA[EXDW]]></dc:creator><pubDate>Mon, 05 Mar 2007 15:14:59 GMT</pubDate></item></channel></rss>