First thanks for all your great tutorials. Secondly do you have any plan to make a video series about socket programming. I don't know maybe a simple chat app that communicate with 2 different people from 2 different locations or IPC through sockets etc... That would be great. Again thanks for everything ❤️
Thank you for your wonderful videos! I found this one looking for a tutorial on using nftw which is a bit more complicated but there doesn't seem to be anything on UA-cam about it. How did you get your video to show up when searching for "nftw c"??? Is there hope that you might make one? :) All the best, R
nice video,bro! very informative. but can you explain me why there are "int argc,char* argv[]"in the arguments of main? i'm just a newbie into this, so i don't know much
Those aren't really needed but I always have them to make people ask about them haha. Here's a video explaining what's up with those: code-vault.net/lesson/dbijqbwu2a:1603733526118
I want to pars folder at one level, don't want to go in all subdirectory recursively. Because required file present one directory below. Eg: There are multiple folder/Sub directory present inside A and B both We don't want to traverse inside those . folder structure is just for reference (but It's on linux) path\A ef.txt path\B ef.txt I want to get name of A and B directory only , and search file inside these not in sub directory. DIR * dir = opendir("path"); if(NULL == dir) return; struct dirent * entity = readdir(dir); can you please suggest how to call readdir only one time and get list of all directory at one level .
You can simply check if entity->d_name ends with .wav There are many ways of doing it, here's one of them: size_t len = strlen(entity->d_name); if (len >= 4 && strcmp(entity->d_name + len - 4, ".wav") == 0) { // this is a wav file }
If you look at the definition of strcmp: www.cplusplus.com/reference/cstring/strcmp/ It returns 0 if the strings compared are the same. So the if condition is checking if the folder is NOT "." and NOT ".." (since we don't want to iterate through those)
That is probably because it is recursive and if u have a very large number of files the recursive stack is huge, from what i read on stackoverflow this is a pretty bad way to do it.
Hi, I've watched your video and it was great, but when i tried to use your code for my needs I ran into problem that buffer is too small. Do you have any idea what can i do to repair that?
@@CodeVault I get it in strcat(path, entity->d_name); also i changed char path[100] = { 0 }; to char path[260] = { 0 }; . Also in error window is something like that File: minkernel\crts\ucrt\inc\corecrt_internal_string_templates.h Line: 50 and I use listFiles("C:\\"); instead of listFiles(".");
In line 15 , you just said if we printed a name of directory we should read the next one. Why would you even make a while loop? Because in this program it's about a one directory which is the current directory and that doesn't need a while loop. What am I not understanding right here?
The code should work even if you have multiple directories inside the directory we are searching. That's why it's a while loop. If you only need the first one then you don't need the loop at all
No. Because the readdir function already allocates the memory for me and returns a pointer to that. Notice I use: entity = readdir(...); And not: *entity = readdir(...); // This would require allocation
@@CodeVault actually their is a dirent.h port for windows that even comes pre package with most compilers expected vs. d_type isnt supported. you need to use the stat() function.
Hmm. An idea I have for the future is to hire someone to take care of subtitles for the videos or other content. Thanks for telling me, this is the first someone mentioned this issue
Spectacular video ! I'm struggling in an assignment to do just this and this video was extremely helpful ! P.S. How did you get to load in VSCode ? GDB is a nightmare...
You are an awesome human being and have helped me out tremendously in my classes! keep it up man you are helping a lot of engineers out in this world
This guy is carrying me through my OS course.
Hey man, just discovered your channel! Thank you so much for your tutorials!
Thanks a lot you are really good at teaching. Loved how you explain things step by step and still keeping good pace.
You know a video is special when you have to log into like it.
Thank you !!
While using the strncmp function make sure your passing the right amount of bytes !! :P
Your videos have been helpful as I am learning system calls in Linux. Thanks again
This really helped me a lot! you explain everything so well, thank you!
thank you so much for your videos sir, you have helped so many people
Great video! Thank you so much for your tutorials.
The best tutorial for c, honestly
thank u so much for explaining everything so clearly, the video was really helpful
First thanks for all your great tutorials. Secondly do you have any plan to make a video series about socket programming. I don't know maybe a simple chat app that communicate with 2 different people from 2 different locations or IPC through sockets etc... That would be great. Again thanks for everything ❤️
I'll look into it!
@@CodeVault thanks
Freggin awesome, man. Thanks for that!
You're the best. Thank you.
Thank you for your wonderful videos! I found this one looking for a tutorial on using nftw which is a bit more complicated but there doesn't seem to be anything on UA-cam about it. How did you get your video to show up when searching for "nftw c"??? Is there hope that you might make one? :)
All the best,
R
Thank you so much!
Thanks so much
thank you so much. really helpful
Cool video. Can you make one about unit testing too? :)
Haven't done unit testing on C but I'll see what I can find. Thanks for the suggestion!
Is it possible to get the locations of all folders from top-level folder
Yeah, you can simply print only when a folder is found and make sure to start from the "/" folder. You might need to launch the program with sudo
Much thanks you dude from school 21!
what extension are you using to auto prompt the type like ->d_name ???
I'm using the C/C++ extension from Microsoft
nice video,bro! very informative. but can you explain me why there are "int argc,char* argv[]"in the arguments of main? i'm just a newbie into this, so i don't know much
Those aren't really needed but I always have them to make people ask about them haha.
Here's a video explaining what's up with those: code-vault.net/lesson/dbijqbwu2a:1603733526118
Sir what autocomplete extension do you use for c
It's the C/C++ extension from Microsoft
I want to pars folder at one level, don't want to go in all subdirectory recursively. Because required file present one directory below.
Eg: There are multiple folder/Sub directory present inside A and B both We don't want to traverse inside those .
folder structure is just for reference (but It's on linux)
path\A
ef.txt
path\B
ef.txt
I want to get name of A and B directory only , and search file inside these not in sub directory.
DIR * dir = opendir("path");
if(NULL == dir)
return;
struct dirent * entity = readdir(dir);
can you please suggest how to call readdir only one time and get list of all directory at one level .
I guess just remove the recursive call from inside the listFiles function.
Great! Thanks a lot
is there any way that i can scan for only .wav files
i want to scan a folder and print all the .wav files present in it
can anyone help?
You can simply check if entity->d_name ends with .wav
There are many ways of doing it, here's one of them:
size_t len = strlen(entity->d_name);
if (len >= 4 && strcmp(entity->d_name + len - 4, ".wav") == 0) {
// this is a wav file
}
Could you explain what your if statement means if it is != 0? I feel as if it's a bit unclear. Thanks!
If you look at the definition of strcmp: www.cplusplus.com/reference/cstring/strcmp/
It returns 0 if the strings compared are the same. So the if condition is checking if the folder is NOT "." and NOT ".." (since we don't want to iterate through those)
If I try to run the program for large directory eg home
it causes "stack smashing". How to avoid that.
Hmm... odd. Maybe try to change the program to iterative instead of recursive
@@CodeVault Sure I will try. Is there a way to make the program tail recursive to optimise recursion.
That is probably because it is recursive and if u have a very large number of files the recursive stack is huge, from what i read on stackoverflow this is a pretty bad way to do it.
@@alexlazea9978 Is that why? huh.
Hi, I've watched your video and it was great, but when i tried to use your code for my needs I ran into problem that buffer is too small. Do you have any idea what can i do to repair that?
Where do you get the error? Maybe you need to have to make the char array larger
@@CodeVault I get it in strcat(path, entity->d_name); also i changed char path[100] = { 0 }; to char path[260] = { 0 }; . Also in error window is something like that
File:
minkernel\crts\ucrt\inc\corecrt_internal_string_templates.h
Line: 50
and I use listFiles("C:\\"); instead of listFiles(".");
can't open sourse file dirent.h solution please
dirent is only on Linux. You have to use the Win32 API if you're on Windows
Hi! I am trying to do the same thing but for new files added in the directory. I really don't know how. Can you suggest me something? Thank you!
How do you define new files? Files that were created not too long ago? Empty files?
So is readdir similar to readline? As in does it read the next file/dir in the current dir?
Yes, exactly
YOU ARA AWESOME MAAAAAAAAAAAAAAAAAAAAN
In line 15 , you just said if we printed a name of directory we should read the next one. Why would you even make a while loop? Because in this program it's about a one directory which is the current directory and that doesn't need a while loop. What am I not understanding right here?
The code should work even if you have multiple directories inside the directory we are searching. That's why it's a while loop. If you only need the first one then you don't need the loop at all
it cant find d_type in my code and I have the same code like you.... what now?
From the documentation it should be there: www.man7.org/linux/man-pages/man3/readdir.3.html
Maybe an import of dirent.h is missing?
@@CodeVault no, my code is on windows
What I'm showing in the video is for Linux only. You'll need to use the Win32 API for these on Windows
Cool, but can you make it in windows too. Thanks!
That's using the Win32 API. I'll look into it
Hello i wanted to know how can I pass different directories instead of “.”
Just pass an absolute or relative path instead of "."
Hello sir, this may be an odd question but shouldn't you allocate space for "entity"? EX: struct dirent *entity = malloc(sizeof(struct dirent) * 100);
No. Because the readdir function already allocates the memory for me and returns a pointer to that. Notice I use:
entity = readdir(...);
And not:
*entity = readdir(...); // This would require allocation
Sir, d_type is not working in codeblocks. It shows error like "struct dirent has no member named d_type". What to do?
This is only for Linux. You gotta use the Win32 API on Windows
@@CodeVault will it work on virtual box ??
Yea, should be
@@CodeVault actually their is a dirent.h port for windows that even comes pre package with most compilers expected vs. d_type isnt supported. you need to use the stat() function.
It would be great if you could add Turkish subtitles to these quality videos.Because
finding resources is a bit of a problem.
Hmm. An idea I have for the future is to hire someone to take care of subtitles for the videos or other content. Thanks for telling me, this is the first someone mentioned this issue
@@CodeVault Thank you for your consideration. I wish you a good day :)
not a good debug ure printf, a printf("here"); will be a better debug 🤣
Maybe with a DEBUG preprocessor flag check, but usually you don't want to have output to stdout just for debugging. Just use gdb instead
Spectacular video ! I'm struggling in an assignment to do just this and this video was extremely helpful ! P.S. How did you get to load in VSCode ? GDB is a nightmare...
dirent is a Linux specific library, it won't work on Windows