Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // exelist.cpp
- // lists all the .exe files in a folder and optionally outputs to a .txt file
- // written by @QuantumWarpCode
- #include <iostream>
- #include <filesystem>
- #include <fstream>
- #include <tchar.h>
- void getEntries(std::wstring path);
- void getEntries(std::filesystem::path path);
- std::wofstream output;
- bool outputs = false;
- void processPath(std::filesystem::path path) {
- if (path.has_extension() == true && path.has_filename() == true) {
- if (path.extension() == ".exe") {
- std::cout << path.filename() << std::endl;
- if (outputs) {
- output << path.filename() << std::endl << path << std::endl << std::endl;
- }
- }
- }
- }
- void processFileEntry(std::filesystem::directory_entry entry) {
- if (entry.is_directory()) {
- getEntries(entry.path());
- }
- else {
- processPath(entry.path());
- }
- }
- void getEntries(std::wstring path) {
- for (const auto & entry : std::filesystem::directory_iterator(path))
- processFileEntry(entry);
- }
- void getEntries(std::filesystem::path path) {
- for (const auto & entry : std::filesystem::directory_iterator(path))
- processFileEntry(entry);
- }
- int wmain(int argc, wchar_t* argv[], wchar_t* envp[])
- {
- if (argc >= 3) {
- std::wstring outputPath = argv[2];
- output.open(outputPath, std::ios_base::out | std::ios_base::app);
- outputs = true;
- std::cout << argv[2] << std::endl << argv[3] << std::endl;
- }
- if (argc >= 2) {
- std::wstring path = argv[1];
- if (outputs) {
- output << "List of .exe files in " << path << std::endl << std::endl << std::endl;
- }
- getEntries(path);
- }
- else {
- std::cout << "Error: Must specify a directory..." << std::endl;
- }
- std::cout << std::endl << std::endl << "Done!" << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement