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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
|
#include <windows.h>
#include <iostream>
#include <fstream>
#include <conio.h>
#include <ctype.h>
#include <string>
#include <string.h>
#include <stdio.h>
#define BUFSIZE 4096
using namespace std;
string filenameOut="example.txt";
int siZe;
int siZekB;
bool bSearchSubdirectories=true;
HANDLE handle;
LPCTSTR strPattern;
std::string temp;
std::string temp1;
std::string temp2;
std::string temp3;
WIN32_FIND_DATA search_data;
int DIRPlace;
string vec[20000][2];
int telDIR=1;
int telFILES=1;
void DeleteFile(){
remove( filenameOut.c_str( ) );
}
void WriteFile(string DType){
ofstream myfile1;
myfile1.open (filenameOut.c_str( ), ios::out | ios::app);
myfile1 <<"\n" << DType << temp.substr(0, temp.size()) << "\\" << temp1;
myfile1.close();
}
void WriteFile1(string FType){
ofstream myfile1;
myfile1.open (filenameOut.c_str( ), ios::out | ios::app);
myfile1 <<"\n" << FType << temp.substr(0, temp.size()) << "\\" << temp1 << " - " << siZe << " bytes (" << siZekB << " kB)";
myfile1.close();
}
std::string string_to_hex(const std::string& input)
{
static const char* const lut = "0123456789ABCDEF";
size_t len = input.length();
std::string output;
output.reserve(2 * len);
for (size_t i = 0; i < len; ++i)
{
const unsigned char c = input[i];
output.push_back(lut[c >> 4]);
output.push_back(lut[c & 15]);
}
return output;
}
int SearchDirectory(string FileSearch ,string refvecFiles,
bool bSearchSubdirectories)
{
WIN32_FIND_DATA search_data;
memset(&search_data, 0, sizeof(WIN32_FIND_DATA));
HANDLE handle = FindFirstFile((refvecFiles+FileSearch).c_str(), &search_data);
temp = refvecFiles;
while(handle != INVALID_HANDLE_VALUE) {
do{
if (search_data.cFileName[0]!='.'){
temp2=search_data.dwFileAttributes;
temp3=string_to_hex(temp2);
DIRPlace=strlen(temp3.c_str())-1;
switch (temp3[DIRPlace-1])
{
case '1': //Directory
temp = refvecFiles;
temp1=search_data.cFileName;
temp2=search_data.dwFileAttributes;
WriteFile("<DIR> ");
vec[telDIR][1]=temp+"\\"+temp1;
vec[telDIR][2]="False";
telDIR++;
break;
default: //Other types (Files etc)
siZe=(search_data.nFileSizeHigh * (MAXDWORD+1)) + search_data.nFileSizeLow;
siZekB=((search_data.nFileSizeHigh * (MAXDWORD+1)) + search_data.nFileSizeLow)/1024;
temp = refvecFiles;
temp1=search_data.cFileName;
temp2=search_data.dwFileAttributes;
WriteFile1("<FILE>");
telFILES++;
break;
}
}
}while (FindNextFile(handle, &search_data) != FALSE);
for (int t=1;t<telDIR;t++){
if (vec[t][2]=="False"){
vec[t][2]="True";
SearchDirectory("\\*",vec[t][1], false);
}
}
break;
}
FindClose(handle);
return 0;
}
int main(int argc, char* argv[])
{
DeleteFile();
SearchDirectory("\\*","C:\\Program Files", false);
std::cout<<"Directories found"<< telDIR<< "\n";
std::cout<<"Files found"<< telFILES<< "\n";
std::cout<<"press any key";
_getch();
}
|