fork download
  1.  
  2.  
  3. #include<iostream>
  4. #include<conio.h>
  5. #include<fstream>
  6. #include<stdio.h>
  7. #include<string>
  8. #include<stdlib.h>
  9. #include<vector>;
  10. #include <direct.h>
  11. #include <cstring>
  12. using namespace std;
  13. struct file {
  14. string name;
  15. char *data;
  16. long size;
  17. };
  18.  
  19. struct folder {
  20. string name;
  21. vector<file>files;
  22. int count;
  23. folder *folders[1000];
  24. };
  25.  
  26. string userfile, s;
  27. char *memoryblock;
  28. ifstream infile;
  29. long long fsize = 0;
  30. ofstream outfile;
  31. folder *myfolders;
  32. folder *head;
  33. folder *prv;
  34.  
  35.  
  36. void print(string path)//to print all paths in memory
  37. {
  38. cout << "this files :" << myfolders->files.size() << "\n";
  39. for (int i = 0; i < myfolders->files.size(); i++)
  40. {
  41. string nn = "";
  42.  
  43. nn = myfolders->files[i].name;
  44. string s = path + "\\" + nn;
  45.  
  46. cout << s << endl;//print files
  47.  
  48. }
  49. cout<< "___________________________________________________\n";
  50. for (int i = 0; i < myfolders->count; i++)
  51. {
  52. string s = path + "\\" + myfolders->folders[i]->name;
  53.  
  54. cout << "folder " << s << ":" <<endl;//print folders
  55. prv = myfolders;
  56. myfolders = myfolders->folders[i];
  57. print(s);
  58. myfolders = prv;
  59.  
  60.  
  61. }
  62. }
  63. void print_all_path()
  64. {
  65. cout << "folder mydisk:\n";
  66. print("my disk");
  67. }
  68. void delete_file()
  69. {
  70. while (1)
  71. {
  72. cout << "if you want delete file from here Enter Yes\n";
  73. cout << "else you want put it in folder Enter folder name\n";
  74. getline(cin, s);
  75. if (s == "Yes")
  76. {
  77. int xx = -1;
  78. cout << "Enter file name from memory \n";
  79.  
  80. getline(cin, s);
  81. for (int i = 0; i < myfolders->files.size(); i++)
  82. {
  83. if (s == myfolders->files[i].name)
  84. xx = i;
  85. }
  86. if (xx != -1)
  87. {
  88. myfolders->files.erase(myfolders->files.begin() + xx);
  89. cout << "Done\n___________________________________________________\n";
  90. }
  91.  
  92. else {
  93. cout << "Not found \n___________________________________________\n";
  94. }
  95. myfolders = head;
  96. break;
  97. }
  98. else
  99. {
  100. for (int i = 0; i < myfolders->count; i++)
  101. if (s == myfolders->folders[i]->name)
  102. myfolders = myfolders->folders[i];
  103.  
  104.  
  105. }
  106. }
  107. }
  108. void delete_folder()
  109. {
  110. while (1)
  111. {
  112. cout << "if you want delete folder from here Enter Yes\n";
  113. cout << "else you want put it in folder Enter folder name\n";
  114. getline(cin, s);
  115. if (s == "Yes")
  116. {
  117. int xx = -1;
  118. cout << "Enter folder name from memory \n";
  119.  
  120. getline(cin, s);
  121. for (int i = 0; i < myfolders->count; i++)
  122. {
  123. if (s == myfolders->folders[i]->name)
  124. {
  125. for (i; i < myfolders->count - 1; i++)
  126. {
  127. myfolders->folders[i] = myfolders->folders[i + 1];
  128.  
  129.  
  130. }
  131. cout << "DONE\n___________________________________________________\n";
  132. myfolders->count--;
  133. break;
  134. }
  135. }
  136. if (xx == -1)
  137. {
  138.  
  139. cout << "not found \n___________________________________________________\n";
  140. }
  141.  
  142.  
  143. myfolders = head;
  144. break;
  145. }
  146. else
  147. {
  148. for (int i = 0; i < myfolders->count; i++)
  149. if (s == myfolders->folders[i]->name)
  150. myfolders = myfolders->folders[i];
  151.  
  152.  
  153. }
  154. }
  155. }
  156. void solve(string path)// To access all files and folders
  157. {
  158.  
  159. for (int i = 0; i < myfolders->files.size(); i++)
  160. {
  161.  
  162. string nn = myfolders->files[i].name;
  163. string s = path + "\\" + nn;
  164. outfile.open(s, ios::binary | ios::out | ios::app);
  165. outfile.write(myfolders->files[i].data, myfolders->files[i].size);
  166. outfile.close();
  167. cout << "Done\n___________________________________________________\n";
  168. }
  169.  
  170. for (int i = 0; i < myfolders->count; i++)
  171. {
  172. string s = path + "\\" + myfolders->folders[i]->name;
  173. char *c = const_cast<char*>(s.c_str());
  174. _mkdir(c);
  175. prv = myfolders;
  176. myfolders = myfolders->folders[i];
  177. solve(s);
  178. myfolders = prv;
  179. }
  180.  
  181. }
  182. void read_file_in_folder()
  183. {
  184. while (1)
  185. {
  186. cout << "if you want put file here Enter Yes\n";
  187. cout << "else you want put it in folder Enter folder name\n";
  188. getline(cin, s);
  189. if (s == "Yes")
  190. {
  191.  
  192. streampos begin, end;
  193. cout << "Enter path of file\n";
  194.  
  195. getline(cin, userfile);
  196. cout << "The file name in your memory and type of it like * jpg ,m4a ,txt .....\n";
  197.  
  198. getline(cin, s);
  199. infile.open(userfile, ios::binary);
  200. if (infile.is_open())
  201. {
  202. begin = infile.tellg();
  203. infile.seekg(0, ios::end);
  204. end = infile.tellg();
  205. fsize = end - begin;
  206.  
  207.  
  208. infile.seekg(0, ios::beg);
  209. memoryblock = new char[fsize];
  210. infile.read(memoryblock, fsize);
  211. infile.close();
  212. file f;
  213. f.name = s;
  214. f.size = fsize;
  215. f.data = new char[fsize];
  216. f.data = memoryblock;
  217. int t = 0;
  218. for (int i = 0; i < myfolders->files.size(); i++)
  219. {
  220. if (s == myfolders->files[i].name)
  221. t = 1;
  222. }
  223. if (t == 0) {
  224. myfolders->files.push_back(f);
  225. cout << "Done\n___________________________________________________\n";
  226. myfolders = head;
  227. }
  228. else
  229. {
  230. cout << "This file exists Please change the name\n___________________________________________________\n";
  231. myfolders = head;
  232. }
  233. }
  234. else
  235. {
  236. cout << "Error opening file\n___________________________________________________\n";
  237. }
  238.  
  239.  
  240. myfolders = head;
  241. break;
  242. }
  243. else
  244. {
  245. for (int i = 0; i < myfolders->count; i++)//To access all the intended folder
  246. if (s == myfolders->folders[i]->name)
  247. myfolders = myfolders->folders[i];
  248.  
  249.  
  250. }
  251. }
  252. }
  253. void write_all_data()
  254. {
  255. cout << "Path for write like D:\\ , E:\\ .... \n";
  256. getline(cin, s);
  257. s = s + "Disk";
  258. char *c = const_cast<char*>(s.c_str());
  259. _mkdir(c);
  260. solve(c);
  261.  
  262. }
  263. void create_folder() {
  264. string s;
  265.  
  266. while (1)
  267. {
  268. cout << "if you want put folder here Enter Yes\n";
  269. cout << "else you want put it in folder Enter folder name\n";
  270.  
  271. getline(cin, s);
  272. if (s == "Yes")
  273. {
  274. int t = 0;
  275. cout << "Enter folder name \n";
  276. getline(cin, s);
  277. for (int i = 0; i < myfolders->count; i++)
  278. {
  279. if (s == myfolders->folders[i]->name)
  280. t = 1;
  281. }
  282. if (t == 0) {
  283. myfolders->folders[myfolders->count] = new folder();
  284. myfolders->folders[myfolders->count]->name = s;
  285. myfolders->folders[myfolders->count]->count = 0;
  286. myfolders->count++;
  287. myfolders = head;
  288. cout << "Done\n___________________________________________________\n";
  289. break;
  290. }
  291. else
  292. {
  293. myfolders = head;
  294. cout << "This folder exists Please change the name\n_____________________________________________\n";
  295. break;
  296. }
  297. }
  298. else
  299. {
  300. for (int i = 0; i < myfolders->count; i++)// To access all the intended folder
  301. {
  302. if (s == myfolders->folders[i]->name)
  303. myfolders = myfolders->folders[i];
  304. }
  305. }
  306. }
  307.  
  308. }
  309. void write_one_file()
  310. {
  311. string s;
  312.  
  313. while (1)
  314. {
  315.  
  316. cout << "if you want write file from here Enter Yes\n";
  317. cout << "else you want write file from folder Enter folder name\n";
  318.  
  319. getline(cin, s);
  320. if (s == "Yes")
  321. {
  322.  
  323. cout << "Enter name of file \n";
  324.  
  325. getline(cin, userfile);
  326. cout << "path of write file like D:\\asd.txt ... \n";
  327.  
  328. getline(cin, s);
  329.  
  330.  
  331.  
  332. int indx = -1;
  333. for (int i = 0; i < myfolders->files.size(); i++)
  334. {
  335. if (userfile == myfolders->files[i].name)
  336. indx = i;
  337. }
  338. if (indx != -1) {
  339. outfile.open(s, ios::binary | ios::out | ios::app);
  340. outfile.write(myfolders->files[indx].data, myfolders->files[indx].size);
  341. outfile.close();
  342. cout << "Done\n____________________________________________________\n";
  343. }
  344. myfolders = head;
  345. break;
  346. }
  347. else
  348. {
  349. for (int i = 0; i < myfolders->count; i++)//To access all the intended folder
  350. {
  351. if (s == myfolders->folders[i]->name)
  352. myfolders = myfolders->folders[i];
  353. }
  354. }
  355. }
  356.  
  357. }
  358. void write_one_folder()
  359. {
  360. string path = "";
  361. while (1) {
  362. cout << "if you want write folder from here Enter Yes\n";
  363. cout << "else you want write file from folder Enter folder name\n";
  364.  
  365. getline(cin, s);
  366. if (s == "Yes")
  367. {
  368. cout << "Enter the path to write it like D:\\ , E:\\ \n";
  369.  
  370. getline(cin, path);
  371. path += "\\" + myfolders->name;
  372. char *c = const_cast<char*>(path.c_str());
  373. _mkdir(c);
  374. solve(c);
  375. /*for (int i = 0; i < myfolders->files.size(); i++)
  376. {
  377. string nn = myfolders->files[i].name;
  378.  
  379. path+="\\"+nn;
  380. outfile.open(path, ios::binary | ios::out | ios::app);
  381. outfile.write(myfolders->files[i].data, myfolders->files[i].size);
  382. outfile.close();
  383. cout << "Done\n";
  384. }*/
  385.  
  386. myfolders = head;
  387. break;
  388. }
  389. else
  390. {
  391. for (int i = 0; i < myfolders->count; i++)//To access all the intended folder
  392. {
  393. if (s == myfolders->folders[i]->name)
  394. myfolders = myfolders->folders[i];
  395. }
  396. }
  397. }
  398. }
  399. int main()
  400. {
  401. cout << " **welcome** \n";
  402. myfolders = new folder();
  403. myfolders->count = 0;
  404. myfolders->name = "disk";
  405. head = myfolders;
  406.  
  407. int x = 9;
  408. while (1) {
  409. string path, G;
  410. cout << "Enter 1 :to create folder\n";
  411. cout << "Enter 2 :to read \n";
  412. cout << "Enter 3 :to write one file \n";
  413. cout << "Enter 4 :to write one folder\n";
  414. cout << "Enter 5 :to write all data\n";
  415. cout << "Enter 6 :to delete file\n";
  416. cout << "Enter 7 :to delete folder\n";
  417. cout << "Enter 8 :to print all paths\n";
  418. cout << "Enter 9 :to clean console\n";
  419. cout << "Enter 10:to Exit\n";
  420. cout << "___________________________________________________\n";
  421. getline(cin, s);
  422. if (s == "1")
  423. {
  424. create_folder();
  425. }
  426. if (s == "2")
  427. {
  428. read_file_in_folder();
  429. }
  430. if (s == "3")
  431. {
  432. write_one_file();
  433.  
  434. }
  435. if (s == "4")
  436. {
  437. write_one_folder();
  438. }
  439. if (s == "5")
  440. {
  441. write_all_data();
  442. }
  443. if (s == "6")
  444. {
  445. delete_file();
  446. }
  447. if (s == "7")
  448. {
  449. delete_folder();
  450. }
  451. if (s == "8")
  452. {
  453. print_all_path();
  454. }
  455.  
  456. if (s == "9")
  457. {
  458. system("CLS");
  459. }
  460. if (s == "10")
  461. {
  462. return 0;
  463. }
  464.  
  465. }
  466. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:4:18: fatal error: conio.h: No such file or directory
 #include<conio.h>
                  ^
compilation terminated.
stdout
Standard output is empty