title: Write into a file names of folders containing in C:\Program Files
body: <p>I have this task:<br />
  1. In current directory create file subMape.dat<br />
  2. Write into it all names of folders, that stored in C:\Program Files folder<br />
  3. Display on the screen data, that was written in subMape.dat</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;windows.h&gt;
  
  using namespace std;
  
  int main() {
      WIN32_FIND_DATA findFileData;
      DWORD bytesWritten = 0;
  
      HANDLE f;
      HANDLE c = CreateFileW(L"subMape.txt", GENERIC_READ | GENERIC_WRITE, NULL, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
  
      //TCHAR lpBuffer[32];
      DWORD nNumberOfBytesToRead = 32;
      //DWORD lpNumberOfBytesRead;
  
      DWORD lengthSum = 0;
  
      if (c) {
          cout &lt;&lt; "CreateFile() succeeded!\n";
          if(f = FindFirstFile(L"C:\\Program Files\\*", &amp;findFileData)){ 
              if(f != INVALID_HANDLE_VALUE) {
  
                  while (FindNextFile(f, &amp;findFileData)){
                      lengthSum += bytesWritten;
                      WriteFile(c, findFileData.cFileName, (DWORD)wcslen(findFileData.cFileName), &amp;bytesWritten, NULL);       
                  }
              }
              FindClose(f);
          }
  
          else {
              cout &lt;&lt; "FindFirstFile() failed :(\n";
          }
  
      }
  
      else {
          cout &lt;&lt; "CreateFile() failed :(\n";
      }
      cout &lt;&lt; lengthSum &lt;&lt; endl;
      //SetFilePointer(c, lengthSum, NULL, FILE_BEGIN);
      //ReadFile(c, lpBuffer, lengthSum, &amp;lpNumberOfBytesRead, NULL);
      //wprintf(lpBuffer);
  
      CloseHandle(c);
  
      return 0;
  }
  </code></pre>
  
  <p>I'm using UNICODE, when it writes findFileData.cFileName - it writes string, where characters splitted with spaces. For example: folder name "New Folder" (strlen = 10) will be written into the file as "N e w  T o" (strlen = 10). What do?</p>