prüfen, ob eine Datei oder ein Verzeichnis existiert
static bool fileexists(string strFile)
/// <summary>/// Prüft, ob die Datei existiert/// </summary>/// <param name="strFile"></param>/// <returns></returns>static bool fileexists(string strFile){ FileInfo fi = new FileInfo(strFile); return fi.Exists;}
static bool folderexists(string strFolder)
/// <summary>/// Prüft, ob der Ordner existiert/// </summary>/// <param name="strFolder"></param>/// <returns></returns>static bool folderexists(string strFolder){ DirectoryInfo di = new DirectoryInfo(strFolder); return di.Exists;}
Links:
Ausgangslage ist eine Datei, in einem Unterverzeichnis: "C:\Test\test.txt". Mit Hilfe der Path Class kann man damit die meisten Pfad-Attribute einer Datei ermitteln.
Was man damit (meines Wissen nach) nicht kann: Den Verzeichnisnamen des übergeordneten Verzeichnisses ermitteln.
Anmerkung: System.IO.Path setzt nicht voraus, dass die Datei auch wirklich existiert.
Links:
Links:
Links:
rekursiv alle leeren Ordner löschen
Quelle: Recursively delete empty folders
Links:
static bool isDirectoryEmpty(string strPath)
/// <summary>/// Prüft, ob ein Verzeichnis leer ist/// </summary>/// <param name="strPath"></param>/// <returns></returns>static bool isDirectoryEmpty(string strPath){ return !Directory.EnumerateFileSystemEntries(strPath).Any();}
Links: