views:

44

answers:

1

I'm making a little file splitter-joiner, and I've already got the splitting process done. Now I need to complete the joiner.

I have this method:

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();
            }                
        }

That method is in a Static Class, and I access it through my Form1, like so:

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)
        {

        }

My method juntarArchivo(which means JoinFile in spanish) recieves a string array, and a string which is the destination folder.

I guess my question in a nutshell is in my method ColeccionDeCortes(string FolderPath), how can I have it return a string[] with all the files locations in the passed FolderPath variable.

For instance, if a user choose FolderX, this method would have to return the locations of all files in FolderX INSIDE OF AN ARRAY(as a collection of "locations" so to speak.

Thank you very much for your help. :)

+3  A: 

I think you're looking for Directory.GetFiles().

jrummell
Delicious. I love it when answers are this short and simple to comprehend. .NET really spoils me sometimes. :D
Sergio Tapia