我需要检查与可执行文件位于同一目录中的文件。
目前我正在使用这段代码 -
if (!File.Exists(versionFile))
{
File.Create(versionFile).Close();
}
在一个地方我正在使用这个:
string file =
Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location)
+ "\\" + args.Executable;
if (File.Exists(file)) {
Process.Start(file);
Application.Exit();
}
两者都在做同样的工作,但我不确定哪一个更强大。我想不出任何一种情况都会失败,但同时我对这两种方法都有一种可疑的感觉。
哪个更健壮,或者对于这个简单的问题还有其他更好的选择吗?