2016-08-29 5 views
0

の表示リストに私は、文字列http://pastebin.com/upTpYUTTのリストを持って、私はこれを行う方法をhttp://pastebin.com/aML6V3uV このように、私はグループと表示リストにしたい、このコードどのグループと文字列

public class tdata 
    { 
     public string fpath { get; set; } 
     public string fsize { get; set; } 
    } 

    private void button1_Click(object sender, EventArgs e) 
    { 
     TorrentFile torrent = Bencode.DecodeTorrentFile("mik.torrent"); 
     /*BString announce = (BString)torrent["encoding"]; 
     object dat = (object)torrent["creation date"]; 
     richTextBox1.SelectionFont = new Font("Tahoma", 11, FontStyle.Regular); 

     BDictionary info = torrent.Info; 

     string mk = info["length"].ToString(); 
     long size = Convert.ToInt64(mk);*/ 

     //richTextBox1.Text = lista.Count.ToString(); 


     List<tdata> name = new List<tdata>(); 

     BList files = (BList)torrent.Info["files"]; 
     foreach (BDictionary file in files) 
     { 
      // File size in bytes (BNumber has implicit conversion to int and long) 
      int size = (BNumber)file["length"]; 

      // List of all parts of the file path. 'dir1/dir2/file.ext' => dir1, dir2 and file.ext 
      BList path = (BList)file["path"]; 

      //int i = 0; 

      String filepath = String.Empty; 

      foreach (IBObject f in path) 
      { 
       filepath += @"\" + f.ToString(); 
      } 

      if (filepath.Substring(0,1) == @"\") 
      { 
       filepath = filepath.Substring(1); 
      } 

      tdata san = new tdata(); 
      san.fpath = filepath; 
      san.fsize = BytesToString(size); 

      name.Add(san); 
     } 

     foreach (tdata mak in name) 
     { 
      richTextBox1.SelectionFont = new Font("Tahoma", 9, FontStyle.Regular); 
      richTextBox1.AppendText("-> " + mak.fpath + "\r\n"); 
      richTextBox1.SelectionFont = new Font("Tahoma", 9, FontStyle.Regular); 
      richTextBox1.AppendText("--> " + mak.fsize + "\r\n"); 
     } 

    } 

    static String BytesToString(long byteCount) 
    { 
     string[] suf = { "B", "KB", "MB", "GB", "TB", "PB", "EB" }; //Longs run out around EB 
     if (byteCount == 0) 
      return "0" + suf[0]; 
     long bytes = Math.Abs(byteCount); 
     int place = Convert.ToInt32(Math.Floor(Math.Log(bytes, 1024))); 
     double num = Math.Round(bytes/Math.Pow(1024, place), 2); 
     return (Math.Sign(byteCount) * num).ToString() + " " +suf[place]; 
    } 

を使用して、このリストを生成?

コメント行は以前のテストのものです。

また、私はこの古い関数はyou.Iはあなたが彼らのフォルダでいくつかのファイルをwanted.Groupingのようなものを行っている助けることができる.maybe持っパス

string path (string data) 
    { 
     string[] p = data.Split('\\'); 

     StringBuilder path = new StringBuilder(); 

     for (int i=0; i < p.Length - 1; i++) 
     { 
      if (i > 0) 
       path.Append("\\"); 
      path.Append(p[i]); 
     } 
     path.Append("\\"); 

     return path.ToString(); 
    } 

答えて

0

を抽出する機能をwrited。

私のように私のクラスでm_Files変数を定義した:私は(System.Windows.Form.Form例えば)私のクラスでは、この機能を持っている場合は

 private void PopulateList(string path) 
    { 
     List<string> files = new List<string>(); 
     foreach (string str in System.IO.Directory.GetFiles(path, "*.jpg")) 
      files.Add(str); 
     if (files.Count > 0) 
      this.m_Files.Add(path, files); 
     foreach (string str in System.IO.Directory.GetDirectories(path)) 
      this.PopulateList(str); 
    } 

 Dictionary<string, List<string>> m_Files = new Dictionary<string, List<string>>(); 

と、私はこれを呼び出します

PopulateList(rootDirectory); 

この場合、このr内のすべてのjpgファイルでm_File辞書を埋めますootディレクトリとそのサブディレクトリを再帰的に使用することができます。明らかに、ファイル拡張子やfileの他のプロパティのように、そのためのパラメータを増やすことができます。

関連する問題