如果存在特定文件夹,则删除所有内容,否则停止脚本

If a specific folder exists then delete all the contents, else stop the script

我需要一个脚本来查找文件夹 "c:\backup" 是否真的存在,删除所有文件夹内容但不删除 "backup" 文件夹本身。

出于安全原因需要一些 "IF" 功能,以免脚本找不到文件夹(出于任何原因)然后开始删除系统中的所有其他文件夹的风险.因此,如果脚本没有找到文件夹,脚本必须中止操作。

希望它有用...这是一些 VB 可能对您有帮助的代码

   Dim dir As New IO.DirectoryInfo("path")
    If dir.Exists Then
      Kill("path\*.*")
    Else
      ' Do whatever else
    End If