Question : Iterate through string array to create files

I have a portion of code that will to a GetFileList(*) from an FTP site. the function returns the string array mess. I then call a download funtion to pull any files in a given directory to a local folder called BoardResp. I am having a problem creating the code to iterate through the string variable mess and creating files locally from the values in the array. The portion of the code seen below where I create the st = File.Create() is where I need to iterate through mess and create the files from it to the local directory C:\FTPFiles\BoardResp. The variable locFileName is set to the path I want to write to. RemFileName should be set to mess.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
FTP.download(FTP.mess, "C:/FTPFiles/BoardResp", false);

           public void download(string remFileName,string locFileName,Boolean resume)
            {
                if(!logined)
                {
                    login();
                }

            setBinaryMode(true);

            Console.WriteLine("Downloading file " + remFileName + " from " + remoteHost +           "/" + remotePath);

            if (locFileName.Equals(""))
            {
                locFileName = remFileName;
            }

            if(!File.Exists(remFileName))
            {
                
                    Stream st = File.Create(mess);
                    st.Close();
            }

Answer : Iterate through string array to create files

Unfortunately, without seeing the code, anything I recommend will be theoretical.  Can you attach the function or class files?

If I understand this correctly, the GetFileList function returns a single string containing a comma-separated list of file names (eg, "file1,file2, file3,file4").  If this is the case, then just add the loop.  I'll use a separate function for easy reading...


// This main function will get the list of names, create the loop, and then call the original Downlod function
public void downloadAll()
{
      // Get the list of file names from the server
      string nameList = GetFileList("*");

      // Get file string into the names array
      string[] fileNames = nameList.Split(char.Parse(","));
      foreach ( string name in file Names )
      {
            // Add logic here to create the local name.
            string localName = "C:\\" + name.ToString().Trim();

            download(name.ToString().Trim(), localName, true);
      }
}

// The original download function
public void download(string remFileName, string locFileName, Boolean resume)
{
      if(!logined)
        {
              login();
      }

      setBinaryMode(true);

      Console.WriteLine("Downloading file " +
            remFileName + " from " + remoteHost +
            "/" + remotePath);

      if (locFileName.Equals(""))
      {
            locFileName = remFileName;
      }

      if(!File.Exists(remFileName))
      {
            Stream st = File.Create(mess);
            st.Close();
      }
}
Random Solutions  
 
programming4us programming4us