[英]How to make sure that if a file exists, it starts a Process.Start?
我目前正在為FiveM服務器創建一個自定義啟動器。 如果在\\AppData\\Local
存在FiveM文件夾,我想運行Process.Start
。
我想這樣做,如果文件夾存在,所以如果安裝了5m,它會啟動軟件,否則會打開一條錯誤消息
這是我的代碼:
private void Button1_Click(object sender, EventArgs e)
{
Environment.GetEnvironmentVariable("LocalAppData");
if (!Directory.Exists("//FiveM"))
{
Process.Start("fivem://connect/144.217.11.186:30120");
MessageBox.Show("Veuillez patienter quelques secondes");
}
else
{
Hide();
error error = new error();
error.Show();
}
}
使用Directory.Exists
檢查文件夾是否存在。
獲取特殊文件夾,添加您的路徑(使用System.IO.Path上的方法 ,而不是通過連接字符串),然后檢查該目錄是否存在:
string folder = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData));
string path = System.IO.Path.Combine(folder, "fivem");
if (Directory.Exists(path)) { ... }
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.