为什么它没有按预期工作?

时间:2017-03-26 11:25:43

标签: c#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using System.Diagnostics;

namespace Test
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            using (FolderBrowserDialog fbd = new FolderBrowserDialog() { Description = "Select your path" })
            {
                if (fbd.ShowDialog() == DialogResult.OK)
                    tbxFrom.Text = fbd.SelectedPath;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            var myLyndaFiles = Directory.GetFiles(tbxFrom.Text, ".lynda");
            var lynda = Directory.GetFiles(tbxProgrammLocation.Text, ".exe");
            for (int i = 0; i < myLyndaFiles.Length; i++) 
            {
                Process.Start(@"C:\WINDOWS\system32\cmd.exe", lynda[0] + " /F " + myLyndaFiles[i] +  " " + tbxTo.Text + "\n");
                tbxOut.Text = i.ToString(); 
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            using (FolderBrowserDialog fbd = new FolderBrowserDialog() { Description = "Select your path" })
            {
                if (fbd.ShowDialog() == DialogResult.OK)
                    tbxTo.Text = fbd.SelectedPath;
            }
        }

        private void btnStartFrom_Click(object sender, EventArgs e)
        {
            using (FolderBrowserDialog fbd = new FolderBrowserDialog() { Description = "Select your path" })
            {
                if (fbd.ShowDialog() == DialogResult.OK)
                    tbxProgrammLocation.Text = fbd.SelectedPath;
            }
        }
    }
}

请有人帮助我!我不知道为什么但是Directory.GetFiles看起来不起作用。我查看了var myLyndaFiles通过断点,但我得到它或多或少为零[0] - &gt;但那里有20多个文件...

1 个答案:

答案 0 :(得分:1)

应该是(在你的扩展文件上添加通配符):

 var myLyndaFiles = Directory.GetFiles(tbxFrom.Text, "*.lynda");
 var lynda = Directory.GetFiles(tbxProgrammLocation.Text, "*.exe");

而不是:

 var myLyndaFiles = Directory.GetFiles(tbxFrom.Text, ".lynda");
 var lynda = Directory.GetFiles(tbxProgrammLocation.Text, ".exe");