public static string GetFileOrFolderName(string path) { if (File.Exists(path)) { return(Path.GetFileName(path)); } if (!Directory.Exists(path)) { throw new ArgumentException("Target '" + path + "' does not exist."); } string[] strArray = Paths.Split(path); return(strArray[strArray.Length - 1]); }
public static string GetFileOrFolderName(string path) { string result; if (File.Exists(path)) { result = Path.GetFileName(path); } else { if (!Directory.Exists(path)) { throw new ArgumentException("Target '" + path + "' does not exist."); } string[] array = Paths.Split(path); result = array[array.Length - 1]; } return(result); }