It is necessary to execute a command like

dir C:\*.txt /b/s >> D:\1.txt 

that is, search for files by mask and save the results to the file 1.txt on disk D.

I tried through system() and ShelExecute , nothing happened. Can anyone help? Maybe there is another way, other than running a DOS command?

It is important that after launching nothing pops up, that is, the program silently performs the search and writes the results to a file.

  • one
    after the drive letter and colon should be backslash: "C: \ path \ to \ file" - andrybak
  • Thank. Can you tell me how to remove the console flashing, that would run quietly? - AlexeyVorobyev

1 answer 1

Using boost (cross platform):

 #include "boost/filesystem.hpp" #include <iostream> int main() { boost::filesystem::recursive_directory_iterator last; for (boost::filesystem::recursive_directory_iterator d("."); d != last; ++d) { // TODO: Вывести *d в какой-нибудь файл } } 

Using the Windows API (FindFirstFile, FindNextFile, FindClose): Listing the Files in a Directory .