C++å®ç°å°ä¸ä¸ªæ件夹ä¸çå¾ç移å°å¦å¤ä¸ä¸ªæ件夹æ¹æ³ï¼
#include <stdio.h>
#include <windows.h>
#include <fstream>
#include <iostream>
#include <string>
#include <cassert>
#include <vector>
using namespace std;
bool fileExists(const std::string& fileName)
{
std::fstream file;
file.open(fileName.c_str(), std::ios::in);
if (file.is_open() == true)
{
file.close();
return true;
}
file.close();
return false;
}
static void copyFile(const std::string& fileNameFrom, const std::string& fileNameTo)
{
assert(fileExists(fileNameFrom));
std::ifstream in (fileNameFrom.c_str());
std::ofstream out (fileNameTo.c_str());
out << in.rdbuf();
out.close();
in.close();
}
bool checkFirst()
{
char* cSplash = "Splash.jpg";
//char* tSplash = "C:\ijji\ENGLISH\Gunz\Splash.jpg";
DWORD attr = GetFileAttributes(cSplash);
if (attr = INVALID_FILE_ATTRIBUTES || (attr & FILE_ATTRIBUTE_DIRECTORY))
return 1;
else
return 0;
}
bool checkSecond()
{
char* tSplash = "C:\\ijji\\ENGLISH\\Gunz\\Splash.jpg";
DWORD attr = GetFileAttributes(tSplash);
if (attr = INVALID_FILE_ATTRIBUTES || (attr & FILE_ATTRIBUTE_DIRECTORY))
return 1;
else
return 0;
}
int main(int argc, char** argv)
{
SetConsoleTitle("Beta Installer 1.0 by Reece Dizon");
string cSplash = "Splash.jpg";
string tSplash = "C:\\ijji\\ENGLISH\\Gunz\\Splash.jpg";
string path = argv[0];
menu:
HANDLE hConsole;
hConsole = GetStdHandle (STD_OUTPUT_HANDLE);
int wWhite = 15;
SetConsoleTextAttribute(hConsole, wWhite);
cout << " --------------------------------------------" << endl;
cout << " Installer 1.0" << endl;
cout << " --------------------------------------------\n" << endl;
cout << "0 - Exit" << endl;
cout << "1 - Install\n" << endl;
string mInput;
cout << "Choose a numer and hit enter to proceed." << endl;
cin >> mInput;
if (mInput == "1")
{
if (checkFirst() == 1) //checkFirst() == 1
{
if (checkSecond() == 1 )
{
system("cls");
if (remove(tSplash.c_str()) != 0)
{
//
}
else
{
bool flag = false;
fstream fin;
fin.open(tSplash.c_str()); //tSplash,ios::n
if (fin.is_open())
{
cout << "File was unable to be removed" << endl;
flag = true;
fin.close();
system("pause>nul");
goto Kill;
}
else
{
cout << "File removed.\n" << endl;
cout << "Continue with installation...." << endl;
fin.close();
system("pause>nul");
goto nMove;
}
}
}
}
else
{
cout << "File not found...\n";
system("pause>nul");
goto Kill;
}
}
else if (mInput == "0")
{
goto Kill;
}
else
{
cout << "That was not an option, please try again!" << endl;
system("pause>nul");
}
system("cls");
goto menu;
nMove:
system("cls");
int result;
copyFile(cSplash, tSplash, TRUE);
cout << "Installation successful!" << endl;
system("pause>nul");
goto Kill;
Kill:
system("cls");
return 0;
}
温馨提示:答案为网友推荐,仅供参考