How to list files, symbolic lniks, directories and subdirectories under a mounted volume using C/C++ in Linux

I want to list files, symbolic links, directories and subdirectories under a mounted volume using C/C++ in Linux.

I have two partitions /dev/sda and /dev/sfdx in my Ubuntu machine.
I want to list all the directories, subdirectories, files and symlinks under it.
How do i achieve it using C/C++.

Currently , i am using below code snippet:

struct dirent *direntp;
direntp->d_name

to list the directories, files under a directories, but it doesn’t work with partitions i.e /dev/sda.

  • Partitions like /dev/sda are raw filesystem devices. You should instead be simply walking the directory tree.

    – 

  • C++ has std::filesystem which would do most of that. C, being a totally different language, has no such support in its standard library.

    – 




  • you’ll need to find the mount points of /dev/sda and traverse the mount points, /dev/sda is a single file

    – 

  • 1

    What is C/C++? Is it ancestor of C++/C#?

    – 




  • 1

    Please choose one language and edit your question to show what you’ve tried so far — preferably in the form of a minimal reproducible example.

    – 

Leave a Comment