Mega Code Archive

 
Categories / C# / File Stream
 

File Path Collection

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; using System.Collections.ObjectModel;     public class FilePathCollection : Collection<string>     {         public FilePathCollection Combine(string prefix)         {             FilePathCollection res = new FilePathCollection();             foreach (string s in this)                 res.Add(Path.Combine(prefix, s));             return res;         }         public long GetTotalFileSize()         {             long res = 0;             for(int i = 0; i < this.Count; i++)             {                 string current = this[i];                 if (System.IO.File.Exists(current))                 {                     FileInfo fi = new FileInfo(current);                     res += fi.Length;                 }                 else                 {                     this.RemoveAt(i);                     i--;                 }                 }             return res;         }     }