Advertisement
CmdBlockGaming

Simple Command Prompt

Aug 24th, 2019
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 8.03 KB | None | 0 0
  1. #include <iostream>
  2. #include <windows.h>
  3. #include <fstream>
  4. #include <stdlib.h>
  5. #include <direct.h>
  6. #include <dirent.h>
  7. #include <unistd.h>
  8. #include <stdio.h>
  9. #include <sys/stat.h>
  10. #include <sys/types.h>
  11. #include <vector>
  12. #include <iostream>
  13. #include <algorithm>
  14. #include <string>
  15. #include <conio.h>
  16. using namespace std;
  17. ofstream UserData;
  18. ifstream MoveData;
  19. ifstream ReadData;
  20. string username;
  21. string option;
  22. string fn;
  23. string ft;
  24. string rfn;
  25. string rftxt;
  26. string exe;
  27. string foldername;
  28. string fc;
  29. string efn;
  30. string pause;
  31. string bcolor = "0";
  32. string tcolor = "7";
  33. string fd;
  34. string dfoldrn;
  35. string oldfilename;
  36. string newfilename;
  37. string mf;
  38. string mfn;
  39. string mfntxt;
  40. string mfntxtc;
  41. DIR* readir;
  42. char dir[60];
  43. string ndir;
  44. bool riw;
  45. int main()
  46. {
  47.     system("COLOR 07");
  48.     cout << "Booting..." << endl;
  49.     Sleep(600);
  50.     cout << "Enter your username: ";
  51.     cin >> username;
  52.     cout << "Welcome " << username << "!" << endl;
  53.     for (;;) {
  54.         system(("COLOR " + bcolor + tcolor).c_str());
  55.         cout << "[@root." << username << "." << dir << "$]";
  56.         cin >> option;
  57.         if (option == "help" || option == "HELP" || option == "Help") {
  58.             cout << "List of commands: " << endl;
  59.             cout << "wrt: Wrties text to a file" << endl;
  60.             cout << "rd: Reads text from a file" << endl;
  61.             cout << "run: runs an executable program (.exe or .com)" << endl;
  62.             cout << "exit: close the program" << endl;
  63.             cout << "mf: Creates a new folder" << endl;
  64.             cout << "colr: changes the console color" << endl;
  65.             cout << "cd: changes the directory" << endl;
  66.             cout << "dir: shows a list of all the files in the current directory" << endl;
  67.             cout << "edt: Edits the content of a file" << endl;
  68.             cout << "clr: clears the console window" << endl;
  69.             cout << "del: deletes a file" << endl;
  70.             cout << "delf: deletes a folder" << endl;
  71.             cout << "rn: Renames a file/folder" << endl;
  72.             cout << "lgout: kills all running applications and logs out" << endl;
  73.             cout << "rst: restarts the computer" << endl;
  74.             cout << "shd: shuts down the computer" << endl;
  75.             cout << "help: Does the exact thing you just saw" << endl;
  76.         }
  77.  
  78.         else if (option == "wrt") {
  79.             cout << "Name of file (including extension): ";
  80.             cin >> fn;
  81.             cin.ignore();
  82.             cout << "Enter file content: ";
  83.             getline(cin, ft);
  84.             UserData.open(fn);
  85.             UserData << ft;
  86.             UserData.close();
  87.             continue;
  88.         }
  89.  
  90.         else if (option == "rd") {
  91.             cin.ignore();
  92.             cout << "Enter the name of the file to be read: ";
  93.             getline(cin, rfn);
  94.             ReadData.open(rfn);
  95.             if (ReadData.is_open()) {
  96.                 while (getline(ReadData, rftxt)) {
  97.                     cout << rftxt << endl;
  98.                 }
  99.                 ReadData.close();
  100.                 continue;
  101.             }
  102.         }
  103.         else if (option == "run") {
  104.             cout << "Run program in same window (Must be a command line app(Y/N))? ";
  105.             cin >> option;
  106.             if (option == "Y" || option == "y") {
  107.                 riw = true;
  108.             }
  109.             else if (option == "N" || option == "n") {
  110.                 riw = false;
  111.             }
  112.             cout << "Enter the name and file extension of the executable (exe or .com): ";
  113.             cin >> exe;
  114.             if (riw == true) {
  115.                 system((exe).c_str());
  116.             }
  117.  
  118.             else if (riw == false) {
  119.                 system(("start " + exe).c_str());
  120.             }
  121.         }
  122.         else if (option == "mf") {
  123.             cin.ignore();
  124.             cout << "Type the name of the folder you want to create: ";
  125.             getline(cin, foldername);
  126.             mkdir((foldername).c_str());
  127.             continue;
  128.         }
  129.         else if (option == "cd") {
  130.             cin.ignore();
  131.             cout << "Folder to go to: ";
  132.             cin.getline(dir, 60);
  133.             ndir = dir;
  134.             _chdir(dir);
  135.         }
  136.         else if (option == "dir") {
  137.             DIR* dir;
  138.             struct dirent* ent;
  139.             if ((dir = opendir("C:")) != NULL) {
  140.                 while ((ent = readdir(dir)) != NULL) {
  141.                     printf("%s\n", ent->d_name);
  142.                 }
  143.                 closedir(dir);
  144.             }
  145.             else {
  146.                 perror("");
  147.                 return EXIT_FAILURE;
  148.             }
  149.         }
  150.         else if (option == "edt") {
  151.             cout << "Name of file to edit: ";
  152.             cin >> efn;
  153.             cin.ignore();
  154.             cout << "New file content: ";
  155.             getline(cin, fc);
  156.             UserData.open(efn);
  157.             UserData << fc;
  158.             UserData.close();
  159.             continue;
  160.         }
  161.         else if (option == "clr") {
  162.             system("cls");
  163.             continue;
  164.         }
  165.         else if (option == "colr") {
  166.             cout << "0 = Black" << endl;
  167.             cout << "1 = Blue" << endl;
  168.             cout << "2 = Green" << endl;
  169.             cout << "3 = Aqua" << endl;
  170.             cout << "4 = Red" << endl;
  171.             cout << "5 = Purple" << endl;
  172.             cout << "6 = Yellow" << endl;
  173.             cout << "7 = White" << endl;
  174.             cout << "8 = Gray" << endl;
  175.             cout << "9 = Light Blue" << endl;
  176.             cout << "A = Light Green" << endl;
  177.             cout << "B = Light Aqua" << endl;
  178.             cout << "C = Light Red" << endl;
  179.             cout << "D = Light Purple" << endl;
  180.             cout << "E = Light Yellow" << endl;
  181.             cout << "F = Bright White" << endl;
  182.             cout << "Enter the color for text: ";
  183.             cin >> tcolor;
  184.             cout << "Enter color for backround: ";
  185.             cin >> bcolor;
  186.             system(("COLOR " + bcolor + tcolor).c_str());
  187.             continue;
  188.         }
  189.         else if (option == "del") {
  190.             cin.ignore();
  191.             cout << "Folder to delete: ";
  192.             getline(cin, fd);
  193.             remove((fd).c_str());
  194.             continue;
  195.         }
  196.         else if (option == "rn") {
  197.             cin.ignore();
  198.             cout << "Name of file/folder: ";
  199.             getline(cin, oldfilename);
  200.             cout << "New name: ";
  201.             getline(cin, newfilename);
  202.             rename((oldfilename).c_str(), (newfilename).c_str());
  203.             continue;
  204.         }
  205.         else if (option == "delf") {
  206.             cin.ignore();
  207.             cout << "Folder to delete: ";
  208.             getline(cin, dfoldrn);
  209.             _rmdir((dfoldrn).c_str());
  210.             continue;
  211.         }
  212.         else if (option == "jfj495sDSDF344k") {
  213.             cout << "Well you just typed that in to get this message" << endl;
  214.             continue;
  215.         }
  216.         else if (option == "mv") {
  217.             cin.ignore();
  218.             cout << "Name of file to move: ";
  219.             getline(cin, mf);
  220.             cout << "New destination: ";
  221.             getline(cin, mfn);
  222.             MoveData.open(mf);
  223.             getline(MoveData, mfntxt);
  224.             mfntxtc = mfntxt;
  225.             MoveData.close();
  226.             remove((mf).c_str());
  227.             _chdir((mfn).c_str());
  228.             UserData.open(mf);
  229.             UserData << mfntxtc;
  230.             UserData.close();
  231.             _chdir((ndir).c_str());
  232.             Sleep(1);
  233.             continue;
  234.         }
  235.         else if (option == "lgout") {
  236.             system("shutdown -f");
  237.         }
  238.         else if (option == "rst") {
  239.             system("shutdown -r");
  240.         }
  241.         else if (option == "shd") {
  242.             system("shutdown -s");
  243.         }
  244.         else if (option == "exit") {
  245.             cout << "Exitng...";
  246.             Sleep(400);
  247.             exit(0);
  248.         }
  249.         else {
  250.             cout << "'" << option << "' is not a valid command. Type 'Help' for a list of commands." << endl;
  251.             continue;
  252.         }
  253.     }
  254. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement