Questions tagged [dirent.h]

header file for POSIX C containing directory-related functions and types.

176 questions
2
votes
1 answer

return a list of files in a folder in C

I have this code which will print to the console all files in a given folder which have a given extension: int scandir(char dirname[], char const *ext) /* Scans a directory and retrieves all files of given extension */ { DIR *d = NULL; …
jramm
  • 6,415
  • 4
  • 34
  • 73
2
votes
1 answer

stat outputting the wrong values for files in a directory

I am trying to create a function that will take an inputted directory path (filrOrDir) and output info for each file in the directory: file name, size, and last access date. The program compiles and prints everything. It prints the right file…
Stc5097
  • 291
  • 1
  • 11
  • 25
2
votes
2 answers

C convert struct dirent * to FILE *

I'm writing a file browser in C that uses the equivalent of ls and cd to let the user navigate the filesystem and select a file. It's all working well - I can get as far as the user selecting a struct dirent * that represents the directory entry of…
sredmond
  • 460
  • 3
  • 15
2
votes
2 answers

iOS - dirent.h - current directory name

I have written virtual system (VFS) that I am using for my apps on Windows. Now, I moved my application to iOS and I have issue with dirrent. Windows port has added info about current folder, where file is. DIR * dir = opendir(dirName); char *…
Martin Perry
  • 9,232
  • 8
  • 46
  • 114
2
votes
2 answers

readdir() showing non visible files

I am using readdir() in Ubuntu to display files and directories. The weird thing is readdir() displays some files starting with "dot", and some that end at ~ . But these files are not in my specified directory. What are these files? I was wondering…
Naruto
  • 1,710
  • 7
  • 28
  • 39
2
votes
5 answers

Discerning between files and folders on a shared drive under Linux

I am trying to list all the files in a certain directory on a shared drive using the following code: #include #include #include "dirent.h" int main () { DIR *directoryHandle = opendir("./temp/"); if (NULL !=…
Mihai Todor
  • 8,014
  • 9
  • 49
  • 86
2
votes
4 answers

How to get the number of files in the specific folder using C or C++ function?

Possible Duplicate: count number of files with a given extension in a directory - C++? How to get the number of files in the specific folder using c or c++ function? Is there any c library function that could get the number of files in a given…
injoy
  • 3,993
  • 10
  • 40
  • 69
1
vote
0 answers

Invalid Modification Date for Linux Directories in stat C

I was working on a shell project, where I encountered a problem to which I can't find a solution to. When using stat() to get modification time, I was getting weird times with Linux directories like /home, /mnt, etc. Code: DIR *d; struct dirent…
1
vote
1 answer

(Using C): Accessing each file in a directory and editing its contents, one by one

I am a beginner programmer (learning how to use things like hash tables and tries at present) and so am not well informed, and would value your advice. I want to write a program that: Receives a directory address as an argv. Goes through each file…
CBCB
  • 13
  • 3
1
vote
1 answer

How to retrieve full file path from DIR pointer?

From a DIR* variable from , how do I get the full file path (e.g. "/home/ubuntu/Desktop/planning")? Note: This needs to work on Linux.
Adam Lee
  • 436
  • 1
  • 14
  • 49
1
vote
1 answer

Last Modified of a File in Folder of C Program

My goal is to try to get the name, size and last modified of a folder. I have used dirent.h to get the first two types. I don't know what the best way of getting the last modified value is, but the current way I am using does not seem very useful. I…
1
vote
1 answer

Sorting files in the directory including case sensitivity in C

I have a C code snippet: I have used dirent.h and used opendir and readdir to read the files I am doing a ls command duplicate using c code , for that the file should be is ascending order and case sensitivity also to be included. #include…
krishnaacharyaa
  • 14,953
  • 4
  • 49
  • 88
1
vote
1 answer

How to get the details of the files in the current working directory in C?

I'm trying to display the files of my current working directory in C, however, I also need to include the details of these files such as the date created and their file sizes. Is there a function that does this in C? So far here is my code: int…
1
vote
2 answers

The meaning behind most of the dirent arguments

I'm having some difficulty understanding the meaning behind all this parameters in the dirent structure. struct dirent{ ino_t d_ino; Inode number off_t d_off; Not an offset; see below unsigned…
B.Castarunza
  • 135
  • 12
1
vote
1 answer

how do i read files in a directory according to their modification time in c++ on windows

Currently I am using dirent.h to iterativly access files in a directory and its sub-directories. It accesses them according to their file names (alphabetically). For some reason I want to access the subdirectories and the files according to their…
gr8_chi
  • 13
  • 4
1 2
3
11 12