title: StreamWriter C# formatting output
body: <p><strong>Problem Statement</strong></p>
  
  <p>In order to run gene annotation software, I need to prepare two types of files, vcard files and coverage tables, and there has to be one-to-one match of vcard to coverage table. Since Im running 2k samples, its hard to identify which file is not one-to-one match. I know that both files have unique identifier numbers, hence, if both folders have files that have same unique numbers, i treat that as "same" file</p>
  
  <hr>
  
  <p>I made a program that compares two folders and reports unique entries in each folder. To do so, I made two list that contains unique file names to each directory. </p>
  
  <p>I want to format the report file (tab delimited .txt file) such that it looks something like below:</p>
  
  <pre><code>Unique in fdr1    Unique in fdr2
  file x    file a
  file y    file b
  file z    file c
  </code></pre>
  
  <p>I find this difficult to do because I have to iterate twice (since I have two lists), but there is no way of going back to the previous line in StreamWriter as far as I know. Basically, once I iterate through the first list and fill the first column, how can I fill the second column with the second list?</p>
  
  <p>Can someone help me out with this?</p>
  
  <p>Thanks</p>
  
  <p>If design of the code has to change (i.e. one list instead of two), please let me know</p>
  
  <p>As requested by some user, this is how I was going to do (not working version)</p>
  
  <pre><code>// Write report
          using (StreamWriter sw = new StreamWriter(dest_txt.Text + @"\" + "Report.txt"))
          {
              // Write headers
              sw.WriteLine("Unique Entries in Folder1" + "\t" + "Unique Entries in Folder2");
  
              // Write unique entries in fdr1
              foreach(string file in fdr1FileList)
              {
                  sw.WriteLine(file + "\t");
              }
  
              // Write unique entries in fdr2
              foreach (string file in fdr2FileList)
              {
                  sw.WriteLine(file + "\t");
              }
              sw.Dispose();
          }
  </code></pre>
  
  <p>As requested for my approach for finding unique entries, here's my code snippet</p>
  
  <pre><code>        Dictionary&lt;int, bool&gt; fdr1Dict = new Dictionary&lt;int, bool&gt;();
          Dictionary&lt;int, bool&gt; fdr2Dict = new Dictionary&lt;int, bool&gt;();
  
          List&lt;string&gt; fdr1FileList = new List&lt;string&gt;();
          List&lt;string&gt; fdr2FileList = new List&lt;string&gt;();
  
          string fdr1Path = folder1_txt.Text;
          string fdr2Path = folder2_txt.Text;
  
          // File names in the specified directory; path not included
          string[] fdr1FileNames = Directory.GetFiles(fdr1Path).Select(Path.GetFileName).ToArray();
          string[] fdr2FileNames = Directory.GetFiles(fdr2Path).Select(Path.GetFileName).ToArray();
  
          // Iterate through the first directory, and add GL number to dictionary
          for(int i = 0; i &lt; fdr1FileNames.Length; i++)
          {
              // Grabs only the number from the file name
              string number = Regex.Match(fdr1FileNames[i], @"\d+").ToString();
              int glNumber;
  
              // Make sure it is a number
              if(Int32.TryParse(number, out glNumber))
              {
                  fdr1Dict[glNumber] = true;
              }
              // If number not present, raise exception
              else
              {
                  throw new Exception(String.Format("GL Number not found in: {0}", fdr1FileNames[i]));
              }
  
          }
  
          // Iterate through the second directory, and add GL number to dictionary
          for (int i = 0; i &lt; fdr2FileNames.Length; i++)
          {
              // Grabs only the number from the file name
              string number = Regex.Match(fdr2FileNames[i], @"\d+").ToString();
              int glNumber;
  
              // Make sure it is a number
              if (Int32.TryParse(number, out glNumber))
              {
                  fdr2Dict[glNumber] = true;
              }
              // If number not present, raise exception
              else
              {
                  throw new Exception(String.Format("GL Number not found in: {0}", fdr2FileNames[i]));
              }
          }
  
         // Iterate through the first directory, and find files that are unique to it
          for (int i = 0; i &lt; fdr1FileNames.Length; i++)
          {
              int glNumber = Int32.Parse(Regex.Match(fdr1FileNames[i], @"\d+").Value);
              // If same file is not present in the second folder add to the list
              if(!fdr2Dict[glNumber])
              {
                  fdr1FileList.Add(fdr1FileNames[i]);
              }
          }
  
          // Iterate through the second directory, and find files that are unique to it
          for (int i = 0; i &lt; fdr2FileNames.Length; i++)
          {
              int glNumber = Int32.Parse(Regex.Match(fdr2FileNames[i], @"\d+").Value);
              // If same file is not present in the first folder add to the list
              if (!fdr1Dict[glNumber])
              {
                  fdr2FileList.Add(fdr2FileNames[i]);
              }
  </code></pre>