gpt4 book ai didi

c# - File.Exists——不想创建新文件

转载 作者:太空宇宙 更新时间:2023-11-03 19:18:04 24 4
gpt4 key购买 nike

我是编码新手 - 请耐心等待。我读了很多书,但无法理解这一点。

因此,当您运行我的新应用程序时,您需要输入一个文件夹名称。该应用程序转到该文件夹​​,然后将扫描该指定文件夹中的 2 个不同的日志文件。但这是我遇到麻烦的地方。如果日志不存在 - 它会询问您是否要创建它正在寻找的文件......我不希望它这样做。我只是希望它转到文件夹,如果文件不存在则不执行任何操作并转到下一行代码。

这是我目前的代码:

private void btnGo_Click(object sender, EventArgs e)
{
//get node id from user and build path to logs
string nodeID = txtNodeID.Text;
string serverPath = @"\\Jhexas02.phiext.com\rwdata\node\";
string fullPath = serverPath + nodeID;
string dbtoolPath = fullPath + "\\DBTool_2013.log";
string msgErrorPath = fullPath + "\\MsgError.log";

//check if logs exist
if (File.Exists(dbtoolPath) == true)
{
System.Diagnostics.Process.Start("notepad.exe", dbtoolPath);
}
{
MessageBox.Show("The 2013 DBTool log does not exist for this Node.");
}

该应用程序将显示 2013 DBTool 日志不存在于此节点。 - 然后它打开记事本并询问我是否要创建该文件。

Cannot find the \\Jhexas02.phiext.com\rwdata\node\R2379495\DBTool_2013.log file.

Do you want to create a new file?

我永远不想创建新文件。有什么好的方法可以解决这个问题?

最佳答案

你在“if”之后跳过了“Else”

if (File.Exists(dbtoolPath) == true)
{
System.Diagnostics.Process.Start("notepad.exe", dbtoolPath);
}
else
{
MessageBox.Show("The 2013 DBTool log does not exist for this Node.");
}

关于c# - File.Exists——不想创建新文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14696479/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com