我正在搜索MIS
幾個*.INI
文件。然後我更改該條目的值並再次保存文件。我現在正在尋找一種方式,程序將顯示不包含MIS
條目的INI文件列表。C#返回標籤中不包含字符串的文件列表
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
pictureBox1.Visible = false;
pictureBox2.Visible = false;
label1.Visible = false;
label3.Visible = false;
label4.Visible = false;
}
private void button1_Click(object sender, EventArgs e)
{
pictureBox1.Visible = false;
pictureBox2.Visible = false;
label1.Visible = false;
label3.Visible = false;
label4.Visible = false;
try
{
DirectoryInfo d = new DirectoryInfo(@".\");
FileInfo[] Files = d.GetFiles("*.INI");
if (Files.Length == 0)
{
label3.Visible = true;
label3.Text = "No INI files found in the directory!";
label3.ForeColor = Color.Red;
label4.Visible = true;
label4.Text = "Ensure the program is run from inside the !MineIT folder";
label4.ForeColor = Color.Red;
}
else
foreach (FileInfo file in Files)
{
string text = File.ReadAllText(file.Name);
const string PATTERN = @"MIS (?<Number>[\d\.]+)";
Match match = Regex.Match(text, PATTERN, RegexOptions.RightToLeft);
if (match.Success == false)
{
label3.Visible = true;
label3.Text = "No MIS entry found in the INI file!";
label3.ForeColor = Color.Red;
label4.Visible = true;
label4.Text = "Ensure MIS has been defined in the INI file";
label4.ForeColor = Color.Red;
}
else
{
int index = match.Groups["Number"].Index;
int lenght = match.Groups["Number"].Length;
text = text.Remove(index, lenght);
text = text.Insert(index, "1");
label1.Text = ("SERVER ENABLED");
label1.ForeColor = Color.Green;
label1.Visible = true;
pictureBox1.Visible = true;
File.WriteAllText(file.Name, text);
}
}
}
catch
{
}
}
private void button2_Click(object sender, EventArgs e)
{
pictureBox1.Visible = false;
pictureBox2.Visible = false;
label1.Visible = false;
label3.Visible = false;
label4.Visible = false;
try
{
DirectoryInfo d = new DirectoryInfo(@".\");
FileInfo[] Files = d.GetFiles("*.INI");
if (Files.Length == 0)
{
label3.Visible = true;
label3.Text = "No INI files found in the directory!";
label3.ForeColor = Color.Red;
label4.Visible = true;
label4.Text = "Ensure the program is run from inside the !MineIT folder";
label4.ForeColor = Color.Red;
}
else
{
foreach (FileInfo file in Files)
{
string text = File.ReadAllText(file.Name);
const string PATTERN = @"MIS (?<Number>[\d\.]+)";
Match match = Regex.Match(text, PATTERN, RegexOptions.RightToLeft);
if (match.Success == false)
{
label3.Visible = true;
label3.Text = "No MIS entry found in the INI file!";
label3.ForeColor = Color.Red;
label4.Visible = true;
label4.Text = "Ensure MIS has been defined in the INI file";
label4.ForeColor = Color.Red;
}
else
{
int index = match.Groups["Number"].Index;
int lenght = match.Groups["Number"].Length;
text = text.Remove(index, lenght);
text = text.Insert(index, "0");
label1.Text = ("SERVER DISABLED");
label1.ForeColor = Color.Red;
label1.Visible = true;
pictureBox2.Visible = true;
File.WriteAllText(file.Name, text);
}
}
}
}
catch
{
}
}
private void button3_Click(object sender, EventArgs e)
{
Close();
}
}
我對編程非常陌生,我希望有人能夠幫助我解決這個問題。
我已經搜索了2天,並沒有找到太多的幫助。
我想要顯示的結果爲:
label3.Text = "No MIS entry found in the INI files: a, b, c, d, e
感謝
非常感謝你這有幫助,它正在工作! –
@HendrikSidaway你可以說,感謝標記答案爲解決方案:) – Nino