Dirent h for windows

Provide feedback

Saved searches

Use saved searches to filter your results more quickly

Sign up

Appearance settings

December 12, 2017 • C++
• 2 minutes to read

Edit

At the time of writing this blog, I am developing a C++ version of my Spiks library — libSpikes. I was compiling the libSpikes using Cygwin and MinGW.

If you have used Linux before you can recognise the way Cygwin folder is structured. Cygwin tends to create a complete POSIX environment on the Windows, that means it brings loads of DLL files to compile C++ files. MinGW, on the other hand, brings the functionality of Win 32 API’s and also provides specific POSIX API’s.

Microsoft released MSVC toolset for VS2017 and VS2015, which is an independent installation of their developer tools.

Linux has a fantastic library called dirent.h, I use it for listing the directory contents, Visual C++ does not provide this library (though they use a different way) and creating a custom directory listing was not an answer. So, dirent is a POSIX port of dirent header to Windows.

To use this, do the following:

  1. If you are using the MSVC toolset, you would have to clone the repository from https://github.com/tronkko/dirent.
  2. Copy the dirent.h from the include folder and paste it in C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Tools\MSVC\14.12.25827\include14.12.25827 is the build number of the tools that I have installed, yours could be different.

That’s it. You should be able to use it as you would use it in a POSIX. Or you could do something like this:

In my project, I have a folder called libWins; this is where I keep all my 3rd party windows related header files. I copied dirent.h to this folder. Then in the root CMakeLists.txt I have the following

set(EXTERNAL_LIBS_WINDOWS "${PROJECT_SOURCE_DIR}/winLibs")

if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
    INCLUDE_DIRECTORIES ( "${EXTERNAL_LIBS_WINDOWS}" )
endif()

If you are using Visual Studio, then you can add the header file to C:\Program Files\Microsoft Visual Studio 14.0\VC\include.

Happy coding.

From Wikibooks, open books for an open world

dirent.h is the header in the C POSIX library for the C programming language that contains constructs that facilitate directory traversing. The function is not part of the C standard, but is considered «pseudo-standard» and is usually portable between platforms.

Name Notes
int closedir(DIR* dirp) Closes the directory stream referred to by dirp. Upon return, dirp may no longer point to an accessible object of the type DIR. If a file descriptor is used to implement type DIR, that file descriptor will be closed. Upon successful completion, closedir() returns 0. Otherwise, -1 is returned and errno is set to indicate the error.

errno Errors: EBADF means dirp does not refer to an open directory stream, EINTR means the function was interrupted by a signal.

DIR* opendir(const char* dirname) Opens a directory stream corresponding to the directory named by dirname. The directory stream is positioned at the first entry. If the type DIR is implemented using a file descriptor, applications will only be able to open up to a total of OPEN_MAX files and directories. Upon successful completion, opendir() returns a pointer to an object of type DIR. Otherwise, a null pointer is returned and errno is set to indicate the error.

errno Errors: EACCES means the search permission is denied for the component of the path prefix of dirname or read permission is denied for dirname. ELOOP means too many symbolic links were encountered in resolving path. ENAMETOOLONG means the length of the dirname argument exceeds PATH_MAX, or a pathname component is longer than NAME_MAX. ENOENT means a component of dirname does not name an existing directory or dirname is an empty string. ENOTDIR means a component of dirname is not a directory. EMFILE means OPEN_MAX file descriptors are currently open in the calling process. ENAMETOOLONG means the pathname resolution of a symbolic link produced an intermediate result whose length exceeds PATH_MAX. ENFILE means there are too many files are currently open in the system.

struct dirent* readdir(DIR* dirp) Returns a pointer to a structure representing the directory entry at the current position in the directory stream specified by the argument dirp, and positions the directory stream at the next entry. It returns a null pointer upon reaching the end of the directory stream. If entries for dot or dot-dot exist, one entry will be returned for dot and one entry will be returned for dot-dot; otherwise they will not be returned. When an error is encountered, a null pointer is returned and errno is set to indicate the error. When the end of the directory is encountered, a null pointer is returned and errno is not changed.

The memory location pointed to by the return value is managed by the library and may change on subsequent calls to readdir. It should not be free’d by the user.

errno Errors: EOVERFLOW means one of the values in the structure to be returned cannot be represented correctly. EBADF means dirp does not refer to an open directory stream. ENOENT means the current position of the directory stream is invalid.

int readdir_r(DIR* dirp, struct dirent* entry, struct dirent** result) Initialises entry to represent the directory entry at the current position in dirp, store a pointer to this structure at the location referenced by result, and positions the directory stream at the next entry. The storage pointed to by entry will be large enough for a dirent with an array of char d_name member containing at least NAME_MAX plus one elements. On successful return, the pointer returned at *result will have the same value as the argument entry. Upon reaching the end of the directory stream, this pointer will have the value NULL.

errno Errors: EBADF means dirp does not refer to an open directory stream.

void rewinddir(DIR* dirp) Resets the position of the directory stream to which dirp refers to the beginning of the directory. It also causes the directory stream to refer to the current state of the corresponding directory, as a call to opendir() would have done. If dirp does not refer to a directory stream, the effect is undefined.
void seekdir(DIR* dirp, long int loc) Sets the position of the next readdir() operation on the directory stream specified by dirp to the position specified by loc. The value of loc should have been returned from an earlier call to telldir(). The new position reverts to the one associated with the directory stream when telldir() was performed. If the value of loc was not obtained from an earlier call to telldir() or if a call to rewinddir() occurred between the call to telldir() and the call to seekdir(), the results of subsequent calls to readdir() are unspecified.
long int telldir(DIR* dirp) Obtains the current location associated with the directory stream specified by dirp. If the most recent operation on the directory stream was a seekdir(), the directory position returned from the telldir() is the same as that supplied as a loc argument for seekdir(). Upon successful completion, telldir() returns the current location of the specified directory stream.

Constants defined in the stdio.h header include:

Name Notes
NAME_MAX (or FILENAME_MAX) The maximum length of the char array d_name.

Data types defined in the dirent.h header include:

  • DIR — A structure representing a directory stream. Its structure is not defined by POSIX, and is usually opaque to users.
  • struct dirent — A structure with the following members:
  • ino_t d_ino — file serial number
  • char d_name[] — name of entry (will not exceed a size of NAME_MAX)
  • In addition, struct dirent may contain the following members, depending on the platform:
  • off_t d_off — file offset
  • unsigned short int d_reclen — length of the dirent record
  • unsigned short int d_namlen — length of name
  • unsigned int d_type — type of file

dirent.h is included in most C/C++ libraries for the PC architecture.

dirent.h is known to be included in the following compilers:

  • Turbo C++ (DOS)
  • GCC (Cross-platform)
  • MinGW (a Microsoft Windows version of GCC)
  • Borland C++ Builder (Microsoft Windows)

Microsoft Visual C++ does not include dirent.h

A short example of dirent.h usage is:

/**************************************************************
 * A simpler and shorter implementation of ls(1)
 * ls(1) is very similar to the DIR command on DOS and Windows.
 **************************************************************/
#include <stdio.h>
#include <dirent.h>

int listdir(const char *path) 
{
  struct dirent *entry;
  DIR *dp;

  dp = opendir(path);
  if (dp == NULL) 
  {
    perror("opendir");
    return -1;
  }

  while((entry = readdir(dp)))
    puts(entry->d_name);

  closedir(dp);
  return 0;
}

int main(int argc, char **argv) {
  int counter = 1;

  if (argc == 1)
	listdir(".");

  while (++counter <= argc) {
    printf("\nListing %s...\n", argv[counter-1]);
    listdir(argv[counter-1]);
  }

  return 0;
}

Put the source in a file (listdir.c) and compile ( in a Linux shell ) like this:

gcc listdir.c -o listdir

or like this:

gcc listdir.c -o listdir.exe

in a Windows/DOS environment.

Now, to run ( in a Linux shell ) type:

 ./listdir

or type:

 listdir.exe

in a Windows/DOS shell.

  • Free Windows implementation of dirent.h
  • OpenGroup specification for dirent.h
  • GNU dirent specifications

📅 2014-Jun-06 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ visual studio ⬩ 📚 Archive

dirent.h is a header file that is found only on Linux systems. It provides data structures and function calls to open and read the contents of directories. If you are trying to port Linux code that uses this header file to Windows, you will that it is not available with Visual Studio.

Thankfully, there is a Windows implementation of dirent.h which can be downloaded here on Github. Just download the zip file, find the dirent.h header file and place it in your Visual Studio include directory. For example, with Visual Studio Express 2015, this directory is C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\include

Tried with: Visual Studio Express 2015 and Windows 7 x64

Last Updated: 11/24/2024
[Time Needed for Reading: ~4-6 minutes]

C/C++/Objective-C Header files, such as dirent.h, are considered a type of Developer (C/C++/Objective-C Header) file. They are associated with the H file extension, developed by Program Arts for C-Free 5.0 Pro.

The first version of dirent.h was released for the Windows 10 Operating System on 04/27/2015 inside Orwell Dev-C++ 5.11.

The most recent release for C-Free 5.0 Pro launched on 01/04/2010 [version 5.0 Pro release].

In this article, you will find detailed dirent.h information, a H file troubleshooting guide, and a list of versions that are available for free download.

What are dirent.h Error Messages?

General dirent.h Runtime Errors

dirent.h file errors often occur during the startup phase of C-Free, but can also occur while the program is running.

These types H errors are also known as “runtime errors” because they occur while C-Free is running. Here are some of the most common dirent.h runtime errors:

  • dirent.h could not be found.
  • dirent.h error.
  • dirent.h failed to load.
  • Error loading dirent.h.
  • Failed to register dirent.h / Cannot register dirent.h.
  • Runtime Error — dirent.h.
  • The file dirent.h is missing or corrupt.

Microsoft Visual C++ Runtime Library

Runtime Error!

Program: C:\Program Files (x86)\C-Free 5\mingw\include\dirent.h

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application’s support team for more information.

Most H errors are due to missing or corrupt files. Your dirent.h file could be missing due to accidental deletion, uninstalled as a shared file of another program (shared with C-Free), or deleted by a malware infection. Furthermore, dirent.h file corruption could be caused from a power outage when loading C-Free, system crash while loading or saving dirent.h, bad sectors on your storage media (usually your primary hard drive), or malware infection. Thus, it’s critical to make sure your anti-virus is kept up-to-date and scanning regularly.

How to Fix dirent.h Errors in 3 Steps (Time to complete: ~5-15 minutes)

If you’re encountering one of the error messages above, follow these troubleshooting steps to resolve your dirent.h issue. These troubleshooting steps are listed in the recommended order of execution.

Step 1: Restore your PC back to the latest restore point, «snapshot», or backup image before error occurred.

To begin System Restore (Windows XP, Vista, 7, 8, and 10):

  1. Hit the Windows Start button
  2. When you see the search box, type «System Restore» and press «ENTER«.
  3. In the search results, find and click System Restore.
  4. Please enter the administrator password (if applicable / prompted).
  5. Follow the steps in the System Restore Wizard to choose a relevant restore point.
  6. Restore your computer to that backup image.

If the Step 1 fails to resolve the dirent.h error, please proceed to the Step 2 below.

Step 2: If recently installed C-Free (or related software), uninstall then try reinstalling C-Free software.

You can uninstall C-Free software by following these instructions (Windows XP, Vista, 7, 8, and 10):

  1. Hit the Windows Start button
  2. In the search box, type «Uninstall» and press «ENTER«.
  3. In the search results, find and click «Add or Remove Programs«
  4. Find the entry for C-Free 5.0 Pro and click «Uninstall«
  5. Follow the prompts for uninstallation.

After the software has been fully uninstalled, restart your PC and reinstall C-Free software.

If this Step 2 fails as well, please proceed to the Step 3 below.

C-Free 5.0 Pro

Program Arts

Step 3: Perform a Windows Update.

When the first two steps haven’t solved your issue, it might be a good idea to run Windows Update. Many dirent.h error messages that are encountered can be contributed to an outdated Windows Operating System. To run Windows Update, please follow these easy steps:

  1. Hit the Windows Start button
  2. In the search box, type «Update» and press «ENTER«.
  3. In the Windows Update dialog box, click «Check for Updates» (or similar button depending on your Windows version)
  4. If updates are available for download, click «Install Updates«.
  5. After the update is completed, restart your PC.

If Windows Update failed to resolve the dirent.h error message, please proceed to next step. Please note that this final step is recommended for advanced PC users only.

If Those Steps Fail: Download and Replace Your dirent.h File (Caution: Advanced)

If none of the previous three troubleshooting steps have resolved your issue, you can try a more aggressive approach (Note: Not recommended for amateur PC users) by downloading and replacing your appropriate dirent.h file version. We maintain a comprehensive database of 100% malware-free dirent.h files for every applicable version of C-Free. Please follow the steps below to download and properly replace you file:

  1. Locate your Windows operating system version in the list of below «Download dirent.h Files».
  2. Click the appropriate «Download Now» button and download your Windows file version.
  3. Copy this file to the appropriate C-Free folder location:

    Windows 10: C:\Program Files (x86)\C-Free 5\mingw\include\
    Windows 10: C:\Perl64\lib\CORE\
    Windows 10: C:\Program Files\MATLAB\R2019b\polyspace\verifier\cxx\include\include-libc\
    Windows 10: C:\Program Files\MATLAB\R2019b\polyspace\verifier\cxx\include\include-libc\bits\
    Windows 10: C:\Program Files\MATLAB\R2019b\sys\perl\win32\lib\CORE\

    Show 2 more directories +

    Windows 10: C:\xampp\perl\lib\CORE\
    Windows 10: C:\Program Files (x86)\Dev-Cpp\MinGW64\x86_64-w64-mingw32\include\

  4. Restart your computer.

If this final step has failed and you’re still encountering the error, you’re only remaining option is to do a clean installation of Windows 10.

GEEK TIP : We must emphasize that reinstalling Windows will be a very time-consuming and advanced task to resolve dirent.h problems. To avoid data loss, you must be sure that you have backed-up all of your important documents, pictures, software installers, and other personal data before beginning the process. If you are not currently backing up your data, you need to do so immediately.

Download dirent.h Files (Malware-Tested 100% Clean)

CAUTION : We strongly advise against downloading and copying dirent.h to your appropriate Windows system directory. Program Arts typically does not release C-Free H files for download because they are bundled together inside of a software installer. The installer’s task is to ensure that all correct verifications have been made before installing and placing dirent.h and all other H files for C-Free. An incorrectly installed H file may create system instability and could cause your program or operating system to stop functioning altogether. Proceed with caution.

Other Files Related to dirent.h

File Name Description Software Program (Version) File Size (bytes) File Location
api-ms-win-core-heap-l… ApiSet Stub DLL Microsoft® Windows® Operating System (10.0.17134.12) 11112 C:\Users\Tester\AppData\Local\Microsoft\OneDriv…
api-ms-win-core-memory… ApiSet Stub DLL Microsoft® Windows® Operating System (10.0.17134.12) 11624 C:\Users\Tester\AppData\Local\Microsoft\OneDriv…
EtwRTDiagLog.etl Microsoft Event Trace Log C-Free 5.0 Pro 13856 C:\Windows\System32\LogFiles\WMI\RtBackup\
EtwRTEventLog-System.etl Microsoft Event Trace Log C-Free 5.0 Pro 432 C:\Windows\System32\LogFiles\WMI\RtBackup\
PerfStringBackup.INI Windows Initialization C-Free 5.0 Pro 1321920 C:\Windows\System32\

You are downloading trial software. The purchase of a one-year software subscription at the price of $29.97 USD is required to unlock all software features. Subscription auto-renews at the end of the term (Learn more). By clicking the «Start Download» button above and installing «Software», I acknowledge I have read and agree to the Solvusoft End User License Agreement and Privacy Policy.

Понравилась статья? Поделить с друзьями:
0 0 голоса
Рейтинг статьи
Подписаться
Уведомить о
guest

0 комментариев
Старые
Новые Популярные
Межтекстовые Отзывы
Посмотреть все комментарии
  • Как отключить автооткрытие флешки в windows 10
  • Как навсегда отключить защитник windows 10 за 3 минуты disable windows defender
  • Как войти в bios на windows 10 asus
  • Docker installation on windows
  • Программа для учета трафика интернета windows