先写.bat文件
@REM 删除指定路径文件
del /f C:\Users\admin\Desktop\abc.txt
@REM 删除指定路径文件夹
rd /s /q C:\Users\admin\Desktop\qwe
@REM 静默清空回收站 询问去掉 /q
rd /s /q c:\$Recycle.Bin
再写一段unity代码:
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
public class SampleScene : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
var path = FormatPath(Application.streamingAssetsPath + "/del.bat");
Debug.LogError(path);
if (!File.Exists(path))
{
Debug.LogError("bat文件不存在");
}
else
{
System.Diagnostics.Process proc = null;
try
{
proc = new System.Diagnostics.Process();
proc.StartInfo.WorkingDirectory = Application.streamingAssetsPath + "/";
proc.StartInfo.FileName = "del.bat";
//proc.StartI

该文章展示了如何在Unity中编写C#代码来运行.bat批处理文件,实现删除指定路径的文本文件和文件夹。代码中包含了对回收站的静默清理,并处理了可能出现的异常情况。
最低0.47元/天 解锁文章
1351

被折叠的 条评论
为什么被折叠?



