HI, I've been looking for a long time now, for some simple ways to get the full path of a file in the same directory of my console and the console itself. The main purpose of my small project is to just locate a file and move it into another directory. I've got the jist of how to do it I just can't find the proper code.
The part where I'm getting most stuck at, is for a check system to see if the files exist before and after they've been moved or not. This is what I got so far..
#include <windows.h>
#include <fstream>
#include <iostream>
#include <string>
using namespace std;
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 FileExists(const char* "Splash.jpg")
{
FILE* fp = NULL;
fp = fopen("Splash.jpg", "rb");
if (fp != NULL)
{
fclose(fp);
return true;
}
return false;
}
*/
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];
string fullPath;
fullPath = Path::GetFullPath(cSplash);
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;
//ifstream cSplash;
//ifstream tSplash;
if (mInput == "1")
{
if (checkFirst() == 1)
{
cout << "works.." << endl << endl;
cout << "GetFullPath('{0}') returns '{1}'", cSplash, fullPath << endl;
system("pause>nul");
goto Kill;
/*if (tSplash)
{
cout << "works so far";
system("pause>nul");
}*/
}
else
{
cout << "\nError...";
system("pause>nul");
goto Kill;
}
}
else
{
cout << "That was not an option, please try again!" << endl;
system("pause>nul");
}
system("pause>nul");
system("cls");
goto menu;
Kill:
system("cls");
return 0;
}
I've already written up what I wanted in C#. I'm pretty much trying to translate it into C++, which I'm still new at.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
namespace Installer
{
class Program
{
static void Main(string[] args)
{
Console.Title = "Beta Installer 1.0 by Reece Dizon";
string a = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
string ijji = @"C:\ijji\ENGLISH\Gunz";
string cSplash = a + @"\Splash.jpg";
string tSplash = ijji + @"\Splash.jpg";
menu:
Console.Clear();
Console.WriteLine(" --------------------------------------------");
Console.WriteLine(" Installer 1.0");
Console.WriteLine(" --------------------------------------------\n\n");
Console.WriteLine("Choose a number and hit enter to proceed... \n\n");
Console.WriteLine("0 - Exit");
Console.WriteLine("1 - Install \n\n");
string input = Console.ReadLine();
if (input == "1")
{
Console.Clear();
if (File.Exists(cSplash))
{
if (File.Exists(tSplash))
{
File.Delete(tSplash);
File.Move(cSplash, tSplash);
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Installation Complete! Proceed to exit isntaller...");
Console.ReadLine();
goto Kill;
}
else
{
Console.WriteLine("An error has occurred. Terminating installer...");
Console.ReadLine();
goto Kill;
}
}
else
{
Console.WriteLine("You Splash.jpg does not exist, please try agian.");
goto menu;
}
}
else if (input == "0")
{
goto Kill;
}
else
{
Console.Clear();
Console.WriteLine("That was not an option, please try again!");
Console.ReadLine();
goto menu;
}
Kill:
Console.Clear();
Environment.Exit(0);
}
}
}