简体   繁体   中英

Counting the total XML-files in a directory

Im trying to write a program that counts the total amounts of XML-files that are in a directory and subdirectories. Here is how I tried:

namespace Jobbuppgift1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        string path1 = "c:\\Jobbuppg";

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            int fileCount = Directory.GetFiles(path1, "*.xml", SearchOption.AllDirectories).Length;
            textBox1.Text = fileCount.ToString();
        }
    }
}

I get no error, but nothing happens.

Need to add extra slash to path1 otherwise "J" is being escaped or "@" works too

namespace Jobbuppgift1
{
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }
    string path1 = "c:\\Jobbuppg";//this or line below
    string path1 = @"c:\Jobbuppg";//this or line above

    private void textBox1_TextChanged(object sender, EventArgs e)
    {
        int fileCount = Directory.GetFiles(path1, "*.xml", SearchOption.AllDirectories).Length;
        textBox1.Text = fileCount.ToString();
    }
}

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM