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

前端 未结 27 3965
情书的邮戳
情书的邮戳 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:26

    System call it!

    system( "dir /b /s /a-d * > file_names.txt" );
    

    Then just read the file.

    EDIT: This answer should be considered a hack, but it really does work (albeit in a platform specific way) if you don't have access to more elegant solutions.

提交回复
热议问题