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);
}