List all files in Local Disk D or C

Hi, anyone can help me? I need to create a program to list all the files in directories and subdirectories. For example if user choose local disk D. The program will display all the files path and name. FYI, im using netbeans ide 8.2.
Hello amateurcpp,

This may not be everything you want, but it is a good place to start. I have found it useful the few times I have used it.

https://www.google.com/#safe=strict&q=dirent.h+download&* Google search
http://softagalleria.net/dirent.php
https://github.com/tronkko/dirent

This is a place to start unless someone has a better idea.

Hope that helps,

Andy
If this is windows, I am wondering how that indexing service works, and if they still use it (it used to be a hog that all computer savvy people turned off). It might be that you can just ask for it, work already been done by the OS.

If that is not the case, you might try to directly read the master file table entries. But I can't recall if those have the path? A little research. You want to avoid crawling the disk looking file by file ... that punishes the disk AND takes forever. There has to be a way to get this info "directly".

std::filesystem::recursive_directory_iterator C++17
http://en.cppreference.com/w/cpp/filesystem/recursive_directory_iterator

std::experimental::filesystem::recursive_directory_iterator filesystem TS
http://en.cppreference.com/w/cpp/experimental/fs

boost::filesystem::recursive_directory_iterator if neither of the above is available
http://www.boost.org/doc/libs/1_63_0/libs/filesystem/doc/reference.html#Class-recursive_directory_iterator

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <iostream>
#include <vector>
#include <string>
#include <chrono>

#include <experimental/filesystem>
namespace fs = std::experimental::filesystem ;

// boost filesystem 
// see: http://www.boost.org/doc/libs/1_63_0/libs/filesystem/doc/index.htm
// #include <boost/filesystem.hpp>
// namespace fs = boost::filesystem ;


std::vector<std::string> get_all_files_recursive( const std::string& path )
{
    std::vector<std::string> file_names ;

    using iterator = fs::recursive_directory_iterator ;
    for( iterator iter(path) ; iter != iterator {} ; ++iter )
        file_names.push_back( iter->path().string() ) ;

    return file_names ;
}

int main()
{
    const std::vector<std::string> file_list = get_all_files_recursive( "C:/Windows/Logs" ) ;
    for( const auto& fn : file_list ) std::cout << fn << '\n' ;
}

std::experimental::filesystem http://rextester.com/XVBO74296
boost::filesystem http://coliru.stacked-crooked.com/a/391a1d96fc82c546
Topic archived. No new replies allowed.