tags:

views:

226

answers:

2
if (!File.Exists("SomeFile.exe"))
{
//Does not exists
}

I have SomeFile.exe in the same path as the exe but the result is Does not Exists.

This does not happen in Windows Form, does something change?

A: 

If your testing it from VS then the current directory is the Project dir not the release/debug folder (where your exe is)

PoweRoy
It does not work
Jonathan Shepherd
Maybe you should give us some more info. Does not exist indicates a file location problem, therefore print out the current path in both applications. The current directory could be different than the folder where your exe is. Hence my answer.
PoweRoy
+2  A: 

Try this to get the file in the executables directory.

string directory = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
string filePath = Path.Combine(directory, "SomeFile.exe");

if (!File.Exists(filePath))
{
    // 1337 code here plx.
}
Patrik