I know file operations are rather non-standard between OS's and API's but I would like to discover whether an execu开发者_开发技巧table (named at run time) exists in the path.
This is a validation of user input and later on the app is called using
ProcessStartInfo ^processStartInfo = gcnew ProcessStartInfo("ReallyCool.exe");
Process ^process = gcnew Process();
process->StartInfo = processStartInfo;
bool processStarted = process->Start();
this throws only when it comes to the last line above.
Does anyone know how I can verify the file is there before taking the risk of actually executing it or am I being a naif by allowing users to run '.exes' through my app?
As per title, I am keen to avoid searching every directory on the path explicitly if possible. Nor am I certain how I could obtain the Windows path from .NET coding.
To check if the file is there, use bool doesFileExist = System.IO.File.Exists(path);
I doubt there is an easy way to know if it is a valid executable without trying to run it.
精彩评论