Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <windows.h>
- using namespace std;
- char text[255] = "",
- type[255] = "",
- path[255] = "E:\\command.txt",
- pathFirst[255] = "",
- pathSecond[255] = "";
- void read() {
- HANDLE file = CreateFile(path, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
- if(file == INVALID_HANDLE_VALUE) {
- cout << "Failed to read command.";
- exit(-1);
- }
- DWORD bytesCount = 0;
- ReadFile(file, text, GetFileSize(file, NULL), &bytesCount, NULL);
- CloseHandle(file);
- }
- void parseText() {
- char* nextToken = NULL;
- char* part = strtok_s((char*)text, " ", &nextToken);
- int i = 1;
- while(part != NULL && i < 4) {
- switch(i) {
- case 1: strcpy_s(type, part); break;
- case 2: strcpy_s(pathFirst, part); break;
- case 3: strcpy_s(pathSecond, part); break;
- }
- part = strtok_s(NULL, " ", &nextToken);
- i++;
- }
- }
- void write() {
- if(pathFirst == "" || pathSecond == "") {
- cout << "Unable to use empty paths." << endl;
- exit(-1);
- }
- try {
- if(!strcmp(type, "copy")) {
- CopyFile(pathFirst, pathSecond, true);
- cout << "Copied.";
- }
- if(!strcmp(type, "move")) {
- MoveFile(pathFirst, pathSecond);
- cout << "Moved.";
- }
- } catch(int error) {
- cout << "Error while launching command: " << error << endl;
- }
- }
- int main()
- {
- cout << " Command path: " << path << endl;
- read();
- cout << " Command text: " << text << endl;
- parseText();
- cout << " Command type: " << type <<
- endl << " Command first path: " << pathFirst <<
- endl << "Command second path: " << pathSecond << endl;
- write();
- exit(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement