homebase
homebase

Reputation: 753

64-bit opendir and readdir in C++Builder

I'm using the VCL tools in C++Builder 11 for Windows desktop development. I am trying to get the C functions opendir and readdir to work in a 64-bit app. I have read the IBM website (link below) about the 64-bit version of opendir and readdir but I can't configure my code to work with the 64-bit versions. The code below shows a single button app with code that reads and displays the name of each file in a folder. This works as a 32-bit app. On the 64-bit platform this code fails in the while loop calling readdir. Can you show how to adjust this code so it works on the 64-bit VCL platform in C++Builder.

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
#include <dirent.h>
#include <System.SysUtils.hpp>


//-----------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//----------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//--------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
  DIR *pDir;
  struct dirent *dirU;

  pDir = opendir( "C:\\test\\" ); 
  if (pDir == NULL) {
    ShowMessage("error");
  }else{
    int count = 1;
    while ((dirU = readdir(pDir)) != NULL) //fails here
    {
      ShowMessage(dirU->d_name);
      count++;
    }
  }
}
//------------------------

IBM 64 bit opendir and readdir

Upvotes: -3

Views: 273

Answers (1)

Mike Versteeg
Mike Versteeg

Reputation: 1623

I'm at a loss why you are looking at the IBM site, feels like a flashback of a long long time ago. Anyway, why not use native functions like GetFiles? See https://docwiki.embarcadero.com/Libraries/Alexandria/en/System.IOUtils.TDirectory.GetFiles

Upvotes: 0

Related Questions