home links tips
code users tools tutorials projects web help design
mudabone
suletzki trans48
nutrition reality
MarthaAttire!
| |
using System; using System.IO;
namespace fileUtils { /// <summary> /// Summary description for fileUtils. /// </summary> public class fileUtils { public fileUtils() { }
public string appPath() { return AppDomain.CurrentDomain.BaseDirectory; }
public string pathPlusFilename(string sPath, string sFilename) { if (sPath.Substring(sPath.Length-1,1) != @"/" && sPath.Substring(sPath.Length-1,1) != @"") { if (sPath.IndexOf(@"") > -1) { sPath += @""; } else if (sPath.IndexOf(@"/") > -1) { sPath += @"/"; } } return sPath + sFilename; }
public void stringToFile(string sFileName, string sData) { FileInfo t = new FileInfo(sFileName); StreamWriter Tex = t.CreateText(); Tex.WriteLine(sData); Tex.Close(); }
public string fileToString(string sFileName) { StreamReader re = File.OpenText(sFileName); string res = re.ReadToEnd(); re.Close(); return res; }
public string stringToTempGUIDFile(string sData, string fileExtension) { //returns file name System.Guid g = System.Guid.NewGuid(); string sFileOut = this.appPath() + g + "." + fileExtension; this.stringToFile(sFileOut,sData); return sFileOut; }
public void createFile(string sFileName) { if (File.Exists(sFileName) == false) this.stringToFile(sFileName,""); }
public void deleteFilter(string sPath, string sFilter) { System.IO.DirectoryInfo di = new DirectoryInfo(sPath); System.IO.FileInfo[] fArr = di.GetFiles(sFilter); foreach (System.IO.FileInfo f in fArr) f.Delete(); }
public System.Collections.Specialized.StringCollection getFiles(string sPath) { return getFiles(sPath,"",false,null); } public System.Collections.Specialized.StringCollection getFiles(string sPath, string sFilter) { return getFiles(sPath, sFilter, false,null); } public System.Collections.Specialized.StringCollection getFiles(string sPath, string sFilter, bool drillDown) { return getFiles(sPath, sFilter, drillDown, null); } private System.Collections.Specialized.StringCollection getFiles(string sPath, string sFilter, bool drillDown, System.Collections.Specialized.StringCollection col) { if (col == null) col = new System.Collections.Specialized.StringCollection();
System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(sPath); System.IO.FileInfo[] files;
if (sFilter != "" && sFilter != null) files = di.GetFiles(sFilter); else files = di.GetFiles(sFilter);
foreach (System.IO.FileInfo f in files) col.Add(f.FullName); if (drillDown == true) { foreach (System.IO.DirectoryInfo d in di.GetDirectories()) this.getFiles(d.FullName, sFilter, drillDown, col); } return col; }
} }
Last Modified 10/2/03 1:12 PM
| Hide Tools
|