Advertisement
QuantumWarpCode

exelist.cpp

Apr 6th, 2020
2,466
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // exelist.cpp
  2. // lists all the .exe files in a folder and optionally outputs to a .txt file
  3. // written by @QuantumWarpCode
  4.  
  5. #include <iostream>
  6. #include <filesystem>
  7. #include <fstream>
  8. #include <tchar.h>
  9.  
  10. void getEntries(std::wstring path);
  11. void getEntries(std::filesystem::path path);
  12. std::wofstream output;
  13. bool outputs = false;
  14.  
  15. void processPath(std::filesystem::path path) {
  16.     if (path.has_extension() == true && path.has_filename() == true) {
  17.         if (path.extension() == ".exe") {
  18.             std::cout << path.filename() << std::endl;
  19.             if (outputs) {
  20.                 output << path.filename() << std::endl << path << std::endl << std::endl;
  21.             }
  22.         }
  23.     }
  24. }
  25.  
  26. void processFileEntry(std::filesystem::directory_entry entry) {
  27.     if (entry.is_directory()) {
  28.         getEntries(entry.path());
  29.     }
  30.     else {
  31.         processPath(entry.path());
  32.     }
  33. }
  34.  
  35. void getEntries(std::wstring path) {
  36.     for (const auto & entry : std::filesystem::directory_iterator(path))
  37.         processFileEntry(entry);
  38. }
  39.  
  40. void getEntries(std::filesystem::path path) {
  41.     for (const auto & entry : std::filesystem::directory_iterator(path))
  42.         processFileEntry(entry);
  43. }
  44.  
  45. int wmain(int argc, wchar_t* argv[], wchar_t* envp[])
  46. {
  47.     if (argc >= 3) {
  48.         std::wstring outputPath = argv[2];
  49.         output.open(outputPath, std::ios_base::out | std::ios_base::app);
  50.         outputs = true;
  51.         std::cout << argv[2] << std::endl << argv[3] << std::endl;
  52.     }
  53.  
  54.     if (argc >= 2) {
  55.         std::wstring path = argv[1];
  56.  
  57.         if (outputs) {
  58.             output << "List of .exe files in " << path << std::endl << std::endl << std::endl;
  59.         }
  60.  
  61.         getEntries(path);
  62.     }
  63.     else {
  64.         std::cout << "Error: Must specify a directory..." << std::endl;
  65.     }
  66.     std::cout << std::endl << std::endl << "Done!" << std::endl;
  67.     return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement