0

我正在制作一个小文件拆分器,我已经完成了拆分过程。现在我需要完成连接器。

我有这个方法:

public static void juntarArchivo(string[] Cortes, string CarpetaDestino) 
        {
            string Nombre = ExtraerNombre(Cortes[0]);
            int CantidadDeCortes = Cortes.Length;

            Nombre = Nombre.Substring(0, Nombre.Length - (CantidadDeCortes.ToString()).Length - 1);
            Nombre = Nombre + "." + ExtraerExtension(Cortes[0]);
            Nombre = CarpetaDestino + @"\" + Nombre;

            FileStream Resultado = new FileStream(Nombre, FileMode.Create);
            foreach (string Corte in Cortes)
            {
                FileStream archivoCorte = new FileStream(Corte, FileMode.Open);
                long Tamano = Corte.Length;
                byte[] Datos = new byte[Tamano];

                archivoCorte.Read(Datos, 0, (int)Tamano);
                Resultado.Write(Datos, 0,(int)Tamano);
                archivoCorte.Close();
            }                
        }

该方法位于静态类中,我通过 Form1 访问它,如下所示:

private void button1_Click(object sender, EventArgs e)
        {
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                textBox1.Text = folderBrowserDialog1.SelectedPath;
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                textBox2.Text = folderBrowserDialog1.SelectedPath;
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            string[] Cortes = ColeccionDeCortes(textBox1.Text);

            try
            {
                Archivos.juntarArchivo(Cortes, textBox2.Text);
                MessageBox.Show("Archivo unido exitosamente.");
            }
            catch (Exception X)
            {
                MessageBox.Show(X.Message);
            }
        }

        private string[] ColeccionDeCortes(string Path)
        {

        }

我的方法 juntarArchivo(意思是西班牙语中的 JoinFile)接收一个字符串数组和一个作为目标文件夹的字符串。

简而言之,我想我的问题是在我的方法 ColeccionDeCortes(string FolderPath) 中,我怎样才能让它返回一个字符串 [],其中包含传递的 FolderPath 变量中的所有文件位置。

例如,如果用户选择 FolderX,则此方法必须在数组内部返回 FolderX 中所有文件的位置(可以说是“位置”的集合。

非常感谢您的帮助。:)

4

1 回答 1

4

我认为您正在寻找Directory.GetFiles()

于 2009-09-17T17:23:15.043 回答