-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClient_Source1.cpp
99 lines (91 loc) · 2 KB
/
Client_Source1.cpp
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
#include <iostream>
#include <dirent.h>
#include <string>
#include <fstream>
using namespace std;
int filesize(string filename)
{
FILE* fp;
ifstream fps;
fps.open(filename.c_str(), ios::binary);
return fps.tellg();
}
int search(string path)
{
string fullpath;
string names;
ofstream file;
ofstream file2;
file.open("files.txt", ios::app);
file2.open("folders.txt", ios::app);
dirent* entry;
DIR* dir;
if (( dir = opendir(path.c_str())) == NULL)
{
cout << "Wrong Address" << endl;
file << "Wrong Address;";
file2 << "Wrong Address;";
return 0;
}
int index = 0;
//file << "FILES FOUND:;;";
//file2 << ";;FOLDERS FOUND:;";
while (entry = readdir(dir))
{
fullpath = path + (string)(entry->d_name);
names = (string)entry->d_name;
if (filesize(fullpath) != -1)
{
index++;
file << fullpath << ";";
}
else
{
if (names.at(0) != '.')
{
file2 << fullpath << ";";
}
}
}
file.close();
file2.close();
closedir(dir);
return index;
}
void list_files()
{
cout << endl << "Files Found:" << endl << endl;
string temp;
ifstream rfile;
rfile.open("files.txt");
char delim = ';';
string str;
string s;
while (getline(rfile, temp, delim))
{
cout << temp << endl;
}
rfile.close();
}
int listfiles(string str)
{
int temp;
remove("files.txt");
remove("folders.txt");
//string str;
//cout << "Enter Path: ";
//cin.ignore(1000, '\n');
//getline(cin, str);
while (str.find("/") != string::npos)
{
str.replace(str.find("/"), 1, "\\");
}
if (str.find_last_of("\\") != (str.size() - 1))
{
str.append("\\");
}
temp = search(str);
//crawl();
list_files();
return temp;
}