In form1 i have two buttons one to select files from directory single file or multiple files.
The second button is to select files from a directory to get all the files in a selected directory.

Now i have a class i'm using to upload the files/directories to my ftp:
At the top of the class i did:

```
public static DirectoryInfo d;
public static string[] files;
private FileInfo[] dirflist;

```

Then i'm using it in the event:

```
private void FtpProgress_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                dirflist = d.GetFiles();
                //if (dirflist.Length > 0)
                //{
                    foreach (string txf in files)
                    {
                        string fn = txf;//txf.Name;
                        BackgroundWorker bw = sender as BackgroundWorker;
                        f = e.Argument as FtpSettings;
                        string UploadPath = String.Format("{0}/{1}{2}", f.Host, f.TargetFolder == "" ? "" : f.TargetFolder + "/", Path.GetFileName(fn));//f.SourceFile));
                        if (!UploadPath.ToLower().StartsWith("ftp://"))
                            UploadPath = "ftp://" + UploadPath;
                        FtpWebRequest request = (FtpWebRequest)WebRequest.Create(UploadPath);
                        request.UseBinary = true;
                        request.UsePassive = f.Passive;
                        request.Method = WebRequestMethods.Ftp.UploadFile;
                        request.Timeout = 300000;
                        request.Credentials = new NetworkCredential(f.Username, f.Password);
                        long FileSize = new FileInfo(f.SourceFile).Length;
                        string FileSizeDescription = GetFileSize(FileSize);
                        int ChunkSize = 4096, NumRetries = 0, MaxRetries = 50;
                        long SentBytes = 0;
                        byte[] Buffer = new byte[ChunkSize];
                        using (Stream requestStream = request.GetRequestStream())
                        {
                            using (FileStream fs = File.Open(f.SourceFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                            {
                                int BytesRead = fs.Read(Buffer, 0, ChunkSize);
                                while (BytesRead > 0)
                                {
                                    try
                                    {
                                        if (bw.CancellationPending)
                                            return;

                                        requestStream.Write(Buffer, 0, BytesRead);

                                        SentBytes += BytesRead;

                                        string SummaryText = String.Format("Transferred {0} / {1}", GetFileSize(SentBytes), FileSizeDescription);
                                        bw.ReportProgress((int)(((decimal)SentBytes / (decimal)FileSize) * 100), SummaryText);
                                    }
                                    catch (Exception ex)
                                    {
                                        Debug.WriteLine("Exception: " + ex.ToString());
                                        if (NumRetries++ < MaxRetries)
                                        {
                                            fs.Position -= BytesRead;
                                        }
                                        else
                                        {
                                            throw new Exception(String.Format("Error occurred during upload, too many retries. \n{0}", ex.ToString()));
                                        }
                                    }
                                    BytesRead = fs.Read(Buffer, 0, ChunkSize);
                                }
                            }
                        }
                        using (FtpWebResponse response = (FtpWebResponse)request.GetResponse())
                            System.Diagnostics.Debug.WriteLine(String.Format("Upload File Complete, status {0}", response.StatusDescription));
                    }
                //}
            }
            catch (WebException ex)
            {
                switch (ex.Status)
                {
                    case WebExceptionStatus.NameResolutionFailure:
                        ConnectionError = "Error: Please check the ftp address";
                        break;
                    case WebExceptionStatus.Timeout:
                        ConnectionError = "Error: Timout Request";
                        break;
                }
            }
        }

```

Now i'm doing loop over the string[] array.
Since i'm selecting multiple files only.

But there might be a case i will select a directory. And then i will need to use the DirectoryInfo(d variable) and the FileInfo[]

If i'm using the FileInfo[] then it's like that:

```
dirflist = d.GetFiles();
                if (dirflist.Length > 0)
                {
                    foreach (FileInfo txf in dirfilist)
                    {
                        string fn = txf.Name;

```

But i don't want to copy over all the code again just for string[] or just for FileInfo[]
I want to make something that i will be able to use FileInfo[] with the foreach or the string[] in the foreach.

And maybe sometimes i will use both upload multiple files and then also to upload a directory with all the files inside.

So maybe it's better to duplicate the whole code and making using once string[] and once FileInfo[] ?
I mean to make two methods one will use FileInfo[] one string[]