public void DeleteAllFile(string fullPath)
{
//path为路径,可以右键文件选择属性看到
//判断路径或文件夹是否存在
if (Directory.Exists(fullPath))
{
//返回所有文件夹的路径
var dirs = Directory.GetDirectories(fullPath);
//遍历所有文件夹路径
for (int index = 0; index < dirs.Length; ++index)
{
//删除文件夹
Directory.Delete(dirs[index]);
}
//返回所有文件的路径
var files = Directory.GetFiles(fullPath);
//遍历所有文件路径
for (int index = 0; index < files.Length; ++index)
{
//删除文件
File.Delete(files[index]);
}
}
//如果路径不存在就报错
else
{
//这里使用的是Unity
Debug.LogError("path not exist");
}
}
2.文件夹重命名
//此处的名字为路径+名字,文件夹无需后缀
public void RenameOld2New(string oldName,string newName)
{
Directory.Move(oldName, newName);
File.Move(oldName, newName);
}