如果我的文件夹中包含.Dat文件,我必须显示一条消息 扩展文件。这该怎么做 。需要帮助赞赏
private void btnChooseFile_Click(object sender, EventArgs e)
{
FileInfo[] files;
FolderBrowserDialog fbd = new FolderBrowserDialog();
//fbd.RootFolder = Environment.SpecialFolder.MyComputer;
fbd.SelectedPath = @txtFilepath.Text.Trim();
if (fbd.ShowDialog() == DialogResult.OK)
{
txtFilepath.Text = fbd.SelectedPath;
if (rbtnOffline.Checked)
{
DefaultManager.OfflineFilePath = @txtFilepath.Text.ToString().Trim();
DirectoryInfo info = new DirectoryInfo(DefaultManager.OfflineFilePath);
files = info.GetFiles("*.dat").OrderBy(p => p.LastWriteTime).ToArray();
if (files.Count() > 0)
{
// MessageBox.Show("no error");
}
else
{
MessageBox.Show("Error, Incorrect capture folder selected", "PGY-SSM", MessageBoxButtons.OK, MessageBoxIcon.Error);
//txtFilepath.Clear();
}
}
else
{
DefaultManager.DumpFilePath = @txtFilepath.Text.ToString().Trim();
}
}}
答案 0 :(得分:1)
要确定文件夹中是否还有其他文件,请将文件夹中的文件总数与dat文件数进行比较:
int fileCount = info.GetFiles().Length;
int datFileCount = info.GetFiles("*.dat").Length;
if (fileCount != datFileCount)
{
MessageBox.Show("Error, other files found …");
}