Hi, just wanna ask if c++ opendir,readdir and closedir code can be implemented in visual c++, i have resently started using this complier and dunno what libraries have changed and if some of these sentences are still valid, and if u can recommend me some kind of "migrating c++ to visual c++" tutorial ill really apreciate it :D

Recommended Answers

All 5 Replies

i would assume if it is MSC++ to MSVC++ then the libraries would be the same? if not there is a brilliant fstream tutorial in the c/c++ tutorials forum that - from the names of the functions - sounds like it could be used to do the same thing; and of course fstream is part of the ANSI standard (ie all compilers support it)

>just wanna ask if c++ opendir,readdir and closedir code can be implemented in visual c++
They're not supported by the library, but you can write versions of them if you really want to using FindFirstFile and FindNextFile.

>just wanna ask if c++ opendir,readdir and closedir code can be implemented in visual c++
They're not supported by the library, but you can write versions of them if you really want to using FindFirstFile and FindNextFile.

thx for the tip, but vc++ has similar functions to browse directories\ get files attributes like readdir/findfirst/next? if u can post the names of that kind of functions it will really help me a lot; or maybe a sample code that implement those.

>if u can post the names of that kind of functions
Are you blind? I gave you the two functions that you need to do what you want to do, whether it's faking POSIX functions, or solving your problem with the straight Windows functions. Now go to MSDN and do the research on them. And in case you missed it the first two times:

FindFirstFile and FindNextFile

Geez.

I know this is very old code from the attic and dusted off a little. It might give you a hint or confuse you totally.

// read the filenames from a given directory

// globals
#define MAXFILES 1500    // maximum filenames in buffer
char fbuf[MAXFILES][80]; // filename buffer
int  fbntotal;           // total number of filenames in buffer

struct {
  char reserved[21];
  char attribute;
  int  time;
  int  date;
  long size;
  char name[13];
} dirdata;  // structure for directory info

...

// read the files in the directory specified in path
// needs full pathname consisting of drive, path and dirname
// reads filenames into a global buffer
void fs_readdir(char *path)
{
  int  k, done;

  done = findfirst(path,&dirdata,0);
  for (k = 0; !done; k++) 
  {
    sprintf(fbuf[k],"%s",dirdata.name);
    done = findnext(&dirdata);
    if (k >= MAXFILES)
      break;
  }
  fbntotal = k;  // total entries in filename buffer
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.