CSharp examples for System.IO:File Path
Get directory of path+File, if only a path is given we will cut off the last sub path!
using System.Text; using System.Linq; using System.IO;// www. j av a 2 s . c o m using System.Collections.Generic; using System.Collections; using System; public class Main{ /// <summary> /// Get directory of path+File, if only a path is given we will cut off /// the last sub path! /// </summary> static public string GetDirectory(string pathFile) { if (pathFile == null) return ""; int i = pathFile.LastIndexOf("\\"); if (i >= 0 && i < pathFile.Length) // Return directory return pathFile.Substring(0, i); // No sub directory found (parent of some dir is "") return ""; } // GetDirectory(pathFile) }