dirent | Extends Node | Runtime Evironment library
kandi X-RAY | dirent Summary
kandi X-RAY | dirent Summary
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue. Please read the contributing guide for advice on opening issues, pull requests, and coding standards.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of dirent
dirent Key Features
dirent Examples and Code Snippets
Community Discussions
Trending Discussions on dirent
QUESTION
I am trying to count files of a directory and its subdirectories. But I am getting a seg fault every time and I don't see why.
I used the code from here: Counting the number of files in a directory using C
Thanks for help
...ANSWER
Answered 2021-Jun-08 at 17:08printf
does not take an integer. It takes a format string and a variable list of arguments. Your problem can probably be fixed by changing:
QUESTION
So the code idea is as following: i pick a path in the main, go in it, if i encounter a file, just save its name and modification date in the .txt file, otherwise it should open the directory it just found, get inside and re-do the process for this directory
The rest of the process works quite fine, UNTIL i uncomment the recursive part, where it will proceed to go in itself i think (Path.), then loops to that state (go to Path.., Path... , etc), making the thing completely useless and justan infinite loop
Any ideas?
...ANSWER
Answered 2021-Jun-04 at 20:51(dir->d_name) !=".."
is not a valid way to check if dir->d_name
is equal to the string ".."
. You need to use strcmp(dir->d_name, "..");
The string literal ".."
refers to a location in memory which contains the 3 bytes .
, .
, and \0
. It is entirely possible for dir->d_name
to also contain those same bytes, but since it is in a different place dir->d_name == ".."
will be false. But strcmp(dir->d_name, "..")
will evaluate to zero if the contents of the two locations are the same.
QUESTION
I wrote a c code on visual studio to compare binary file to search a know virus in other binary file.
the code is running on my windows PC perfectly however it won't compile on the Linux test of my collage.
the code receive a folder containing the files and the file of the virus
this is the code adjusted for Linux that i sent to the test
ANSWER
Answered 2021-May-15 at 17:43Pasting your code into godbolt quickly reveals the problem. struct stat
isn't defined. For linux, you need to #include
and #include
for struct stat
. Pay attention to the remaining warning(s).
QUESTION
I am listing elements in a directory in C.
I use the following code:
...ANSWER
Answered 2021-May-15 at 09:17- Values because they are enums. ref: https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.7-4.6/+/refs/heads/jb-dev/sysroot/usr/include/dirent.h
- Types are not consistent across OS so need to check "dirent.h" or "sys/types.h" of that OS. ref: https://c-for-dummies.com/blog/?p=3252
You can also use stat function to know if its a file or directory from "sys/stat.h"
below example in case you want to print file or dir:
QUESTION
I open a directory that has multiple subdirectories with names of countries. What i want is to make a list and store the paths of these directories in the nodes. The issue comes up when i print the list and in the destructor. I don't seem to get what's wrong since i've used these functions multiple times before with no issue coming up.
The directory looks something like this:
...ANSWER
Answered 2021-May-04 at 20:17You never set newnode->next
to NULL
. So when you loop through the list of nodes, you run into an unitialized pointer when you get to the last node.
You can change the CountryNode
constructor to initialize it to this default.
QUESTION
I'm new to this kind of programming so i'm sorry in advance if it's a dump question.I'm trying to do a very simple task but i don't seem to get what goes wrong.
I have a parent process that creates a number of children processes, and with the usage of FIFOs i want to send a message to all of the children (e.g "hi"), the message get's received by the processes but there is an error coming up no matter what i do and can't seem to find what's wrong.
Here is the parent's main function:
...ANSWER
Answered 2021-May-03 at 20:23In send_message
, you always write 9 bytes from buffer
, but not all of those bytes have had a value written to them. This is because the sprintf
that populates buffer
only writes to the first few locations, possibly as few as 3.
The solution is to either initialize them all to 0
QUESTION
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 am getting type errors when trying to get my path as the dirent folder that I am opening. I'm not sure if there is an easier way to do this or but any guidance would be much appreciated. I found an example of how to get the last modified on stackoverflow and was trying to use that... below is my code:
...ANSWER
Answered 2021-Apr-29 at 02:04folder
is the return value of opendir(".");
. opendir
returns either a DIR* structure or NULL. Not the directory path expressed using characters.
When you call getFileCreationTime(folder);
you are sending a DIR*
to your function. But you are expecting a char* path
. So do not pass a DIR*
, pass it the characters representing your directory. In your case "."
(as used in your opendir()
statement above).
Obviously, your directory name could be stored in a variable.
QUESTION
Is below code adding valid strings to the vector?
...ANSWER
Answered 2021-Apr-27 at 22:20Yes, this code is fine 1, and it will invoke the std::string(const char*)
constructor as expected, since dp->d_name
is a (null-terminated) char[]
array that will decay into a char*
pointer.
1: provided that push_back()
does not raise an exception, otherwise the DIR*
will be leaked.
Note that calling push_back()
with a char*
will make a temporary std::string
that will have to be copied/moved into another std::string
that is constructed internally by the vector. In C++11 and later, you can use emplace_back()
instead to avoid making that initial temporary:
QUESTION
I'm trying to make a C program that will display all the files and folders containing a given search term. The search term is given as an argument when executing the program. A folder / file is displayed to standard output if its name contains the search term (case insensitive). The difficulty though is that I do not want to output files and subfolders that are contained in a folder that contains the search term. Here's an example:
Let's assume my search term is docker, this is the current output:
...ANSWER
Answered 2021-Apr-24 at 19:32Thanks to @KamilCuk I was able to solve my issue. Here's my final listFilesRecursively
function:
QUESTION
I am trying to compile this excerpt of code without errors:
...ANSWER
Answered 2021-Apr-10 at 10:42The type of the last argument for select_printer
doesn't match what XtAddCallback
expected for its callback.
The select_printer
function have a XmPushButtonCallbackStruct *
argument, while the callback should have a void *
argument.
My suggested fix is to change the last argument of select_printer
to a void *
, and then inside select_printer
cast the argument to its correct type. Like:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install dirent
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page