dirent.h

How do i check if a file is a regular file in C++?

How do i check in C++ if a file is a regular file (and is not a directory, a pipe, etc.)? I need a function isFile(). DIR *dp; struct dirent *dirp; while ((dirp = readdir(dp)) != NULL) { if ( isFile(dirp)) { cout << "IS A FILE!" << endl; i++; } I've tried comparing dirp->d_type with (unsigned char)0x8, but it seems not portable...

Are there ways of doing opendir(), readdir() type of calls through SSH/SFTP?

I have a bit of code that reads a directory for files to process. I currently use the dirent.h,opendir(),readdir() methods of doing this. I have been told that I need to do the same thing, only now it is a directory on a remote machine with SSH/SFTP access. The only way (that I can think of) to do the same thing, without changing anyth...

Cross platform way of testing whether a file is a directory

Currently I have some code like (condensed and removed a bunch of error checking): dp = readdir(dir); if (dp->d_type == DT_DIR) { } This works swimmingly on my Linux machine. However on another machine (looks like SunOS, sparc): SunOS HOST 5.10 Generic_127127-11 sun4u sparc SUNW,Ultra-5_10 I get the following error at compile time...

How to use dirent.h correctly.

Hello, I am new to C++ and I am experimenting with the dirent.h header to manipulate directory entries. The following little app compiles but pukes after you supple a directory name. Can someone give me a hint? The int quit is there to provide a while loop. I removed the loop in an attempt to isolate my problem. thanks! #include <iost...

Do you know a Haskell package for dirent.h on Windows?

Hi, Do you know a Haskell package for dirent.h on Windows? There is similar set of functions in system.posix but those functions are not implemented on Windows. I wonder if there is similar somewhere else. Thanks. ...

Accessing Directories in C

The program is to open a directory and to display the name of the files... i.e if there is a file..it should say FILE....else DIRECTORY.. but the program displays all the files as directory.. Could anyone pls check the code for any errors....thnx #include<stdio.h> #include<dirent.h> #define DIR_path "root/test" main() { DIR...

How can DIR* get EBADF error?

I have some code that I have inherited which is part of a class for iterating, accessing the directory content and uses boost::filesystem::path. The code reads in part: struct directory_iterator_impl { private: void skip_dots(const path& p, const char* who) { static const std::string d("."); static const std::string dd(".."...

How do I check if a directory is a file or folder?

Okay, so I'm using mingW, and the direct struct has no variables named d_type or stat, d_stat, or dd_stat. I need to know how I can use my direct struct to figure out if what I have is a file or folder. Here is my code. #include <sys/types.h> #include <sys/stat.h> #include <dirent.h> #include <errno.h> #include <vector> #include <string...

How can I generate a directory tree from a root folder and all it's sub folders?

okay, so I'm trying to get a directory of folders and sub folders, but it just goes into a infinite loop. What is a better way to create a directory of folders and sub-folders? Cause I really have no idea. this is my code so far: #include <sys/types.h> #include <sys/stat.h> #include <dirent.h> #include <errno.h> #include <vector> #incl...