How can I get the list of files in a directory using C or C++?

前端 未结 27 3151
情书的邮戳
情书的邮戳 2020-11-21 05:30

How can I determine the list of files in a directory from inside my C or C++ code?

I\'m not allowed to execute the ls command and parse the results from

27条回答
  •  清酒与你
    2020-11-21 06:20

    GNU Manual FTW

    http://www.gnu.org/software/libc/manual/html_node/Simple-Directory-Lister.html#Simple-Directory-Lister

    Also, sometimes it's good to go right to the source (pun intended). You can learn a lot by looking at the innards of some of the most common commands in Linux. I've set up a simple mirror of GNU's coreutils on github (for reading).

    https://github.com/homer6/gnu_coreutils/blob/master/src/ls.c

    Maybe this doesn't address Windows, but a number of cases of using Unix variants can be had by using these methods.

    Hope that helps...

提交回复
热议问题