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?
To check whether a Path object exists independently of whether is it a file or directory, use my_path. exists() .
To check for specific files use File. Exists(path) , which will return a boolean indicating wheter the file at path exists.
For creating a directory, we must first import the System.IO namespace in C#. The namespace is a library that allows you to access static methods for creating, copying, moving, and deleting directories.
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.
}
If your testing it from VS then the current directory is the Project dir not the release/debug folder (where your exe is)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With