C#删除文件或文件夹

//程序根目录相对路径
string filePath = Application.StartupPath + "\\file.txt";
//绝对路径
string filePathAb = "C:\\file.txt";
FileInfo file = new FileInfo(filePath);
file.Delete();
//文件夹路径
string folderPath = Application.StartupPath + "\\Temp\\";
DirectoryInfo folder = new DirectoryInfo(folderPath);
//true表示删除所有子文件(夹)
folder.Delete(true);
C#

Powered by WordPress. Theme by Alx.