List files in a directory (recursively too!)

Поділитися
Вставка
  • Опубліковано 4 січ 2025

КОМЕНТАРІ • 78

  • @robertwitt1276
    @robertwitt1276 3 роки тому +26

    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

  • @Squish888
    @Squish888 3 роки тому +12

    This guy is carrying me through my OS course.

  • @amyrs1213
    @amyrs1213 4 роки тому +6

    Hey man, just discovered your channel! Thank you so much for your tutorials!

  • @bozdogan_
    @bozdogan_ 3 роки тому +7

    Thanks a lot you are really good at teaching. Loved how you explain things step by step and still keeping good pace.

  • @markthompson6552
    @markthompson6552 11 місяців тому

    You know a video is special when you have to log into like it.

  • @patrickslomian7423
    @patrickslomian7423 6 місяців тому +1

    Thank you !!
    While using the strncmp function make sure your passing the right amount of bytes !! :P

  • @thetablue8507
    @thetablue8507 3 роки тому

    Your videos have been helpful as I am learning system calls in Linux. Thanks again

  • @Benjaskz
    @Benjaskz 3 роки тому +2

    This really helped me a lot! you explain everything so well, thank you!

  • @nope7505
    @nope7505 2 роки тому

    thank you so much for your videos sir, you have helped so many people

  • @michagolemo3765
    @michagolemo3765 3 роки тому +1

    Great video! Thank you so much for your tutorials.

  • @izotovadaria7151
    @izotovadaria7151 3 роки тому

    The best tutorial for c, honestly

  • @dhruv_195
    @dhruv_195 2 роки тому

    thank u so much for explaining everything so clearly, the video was really helpful

  • @novigradmerchant2400
    @novigradmerchant2400 4 роки тому +6

    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 ❤️

  • @TheScoobysteve
    @TheScoobysteve 3 роки тому

    Freggin awesome, man. Thanks for that!

  • @adarshramlaul3299
    @adarshramlaul3299 Рік тому

    You're the best. Thank you.

  • @robmayol
    @robmayol Рік тому

    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

  • @odiljonabduvaitov
    @odiljonabduvaitov 3 роки тому +1

    Thank you so much!

  • @weihyac
    @weihyac 3 роки тому +1

    Thanks so much

  • @newseven385
    @newseven385 2 роки тому

    thank you so much. really helpful

  • @dominikheinz2297
    @dominikheinz2297 4 роки тому +2

    Cool video. Can you make one about unit testing too? :)

    • @CodeVault
      @CodeVault  4 роки тому

      Haven't done unit testing on C but I'll see what I can find. Thanks for the suggestion!

  • @kamleshkailasjoshi2620
    @kamleshkailasjoshi2620 2 роки тому

    Is it possible to get the locations of all folders from top-level folder

    • @CodeVault
      @CodeVault  2 роки тому

      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

  • @newcomer3419
    @newcomer3419 2 роки тому

    Much thanks you dude from school 21!

  • @hamzahalamdeen2057
    @hamzahalamdeen2057 Рік тому

    what extension are you using to auto prompt the type like ->d_name ???

    • @CodeVault
      @CodeVault  Рік тому

      I'm using the C/C++ extension from Microsoft

  • @Anim233
    @Anim233 3 роки тому +1

    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

    • @CodeVault
      @CodeVault  3 роки тому

      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

  • @alphaedits1808
    @alphaedits1808 2 роки тому

    Sir what autocomplete extension do you use for c

    • @CodeVault
      @CodeVault  2 роки тому

      It's the C/C++ extension from Microsoft

  • @anshugangwar7344
    @anshugangwar7344 2 роки тому

    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 .

    • @CodeVault
      @CodeVault  2 роки тому

      I guess just remove the recursive call from inside the listFiles function.

  • @Rust185
    @Rust185 2 роки тому

    Great! Thanks a lot

  • @theawesome-est34
    @theawesome-est34 2 роки тому

    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?

    • @CodeVault
      @CodeVault  2 роки тому

      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
      }

  • @TheAbsoluteSir
    @TheAbsoluteSir 3 роки тому

    Could you explain what your if statement means if it is != 0? I feel as if it's a bit unclear. Thanks!

    • @CodeVault
      @CodeVault  3 роки тому

      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)

  • @ishangupta8731
    @ishangupta8731 3 роки тому

    If I try to run the program for large directory eg home
    it causes "stack smashing". How to avoid that.

    • @CodeVault
      @CodeVault  3 роки тому

      Hmm... odd. Maybe try to change the program to iterative instead of recursive

    • @ishangupta8731
      @ishangupta8731 3 роки тому

      @@CodeVault Sure I will try. Is there a way to make the program tail recursive to optimise recursion.

    • @alexlazea9978
      @alexlazea9978 2 роки тому

      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.

    • @vibranteye4369
      @vibranteye4369 2 роки тому

      @@alexlazea9978 Is that why? huh.

  • @Carlos_hum
    @Carlos_hum 2 роки тому

    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
      @CodeVault  2 роки тому

      Where do you get the error? Maybe you need to have to make the char array larger

    • @Carlos_hum
      @Carlos_hum 2 роки тому

      ​@@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(".");

  • @ibrarahmad8488
    @ibrarahmad8488 2 роки тому

    can't open sourse file dirent.h solution please

    • @CodeVault
      @CodeVault  2 роки тому

      dirent is only on Linux. You have to use the Win32 API if you're on Windows

  • @iulianab
    @iulianab 3 роки тому

    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!

    • @CodeVault
      @CodeVault  3 роки тому +1

      How do you define new files? Files that were created not too long ago? Empty files?

  • @jeremiahlee9703
    @jeremiahlee9703 2 роки тому

    So is readdir similar to readline? As in does it read the next file/dir in the current dir?

  • @saraaljbn859
    @saraaljbn859 3 роки тому

    YOU ARA AWESOME MAAAAAAAAAAAAAAAAAAAAN

  • @sakkamouid3343
    @sakkamouid3343 2 роки тому

    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?

    • @CodeVault
      @CodeVault  2 роки тому +1

      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

  • @felixmaster7606
    @felixmaster7606 Рік тому

    it cant find d_type in my code and I have the same code like you.... what now?

    • @CodeVault
      @CodeVault  Рік тому

      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?

    • @felixmaster7606
      @felixmaster7606 Рік тому

      @@CodeVault no, my code is on windows

    • @CodeVault
      @CodeVault  Рік тому

      What I'm showing in the video is for Linux only. You'll need to use the Win32 API for these on Windows

  • @yoan224
    @yoan224 3 роки тому +2

    Cool, but can you make it in windows too. Thanks!

    • @CodeVault
      @CodeVault  3 роки тому +1

      That's using the Win32 API. I'll look into it

  • @erik.rodriguez
    @erik.rodriguez 3 роки тому

    Hello i wanted to know how can I pass different directories instead of “.”

    • @CodeVault
      @CodeVault  3 роки тому

      Just pass an absolute or relative path instead of "."

  • @vibranteye4369
    @vibranteye4369 2 роки тому

    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);

    • @CodeVault
      @CodeVault  2 роки тому

      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

  • @sanmeetwakchaure8530
    @sanmeetwakchaure8530 3 роки тому

    Sir, d_type is not working in codeblocks. It shows error like "struct dirent has no member named d_type". What to do?

    • @CodeVault
      @CodeVault  3 роки тому +1

      This is only for Linux. You gotta use the Win32 API on Windows

    • @sanmeetwakchaure8530
      @sanmeetwakchaure8530 3 роки тому

      @@CodeVault will it work on virtual box ??

    • @CodeVault
      @CodeVault  3 роки тому +1

      Yea, should be

    • @hershey3
      @hershey3 3 роки тому

      @@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.

  • @fakihe8147
    @fakihe8147 2 роки тому

    It would be great if you could add Turkish subtitles to these quality videos.Because
    finding resources is a bit of a problem.

    • @CodeVault
      @CodeVault  2 роки тому +1

      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

    • @fakihe8147
      @fakihe8147 2 роки тому

      @@CodeVault Thank you for your consideration. I wish you a good day :)

  • @Bastian-dm2pc
    @Bastian-dm2pc Рік тому

    not a good debug ure printf, a printf("here"); will be a better debug 🤣

    • @CodeVault
      @CodeVault  Рік тому

      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

  • @lkilgoretrout
    @lkilgoretrout 2 роки тому

    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...

    • @CodeVault
      @CodeVault  2 роки тому

      dirent is a Linux specific library, it won't work on Windows