从%LOCALAPPDATA%批量删除文件夹

时间:2014-09-21 10:16:34

标签: javascript powershell batch-file windows-7

我需要从所有用户本地配置文件中删除特定文件夹 C:\Users\{username}\AppData\Local\

我创建了一个简短的脚本来执行此操作,我必须以管理员身份运行它,因为我先运行另一个程序。

call c:\test.exe

rd /s /q %LOCALAPPDATA%\test

问题是,这只会删除管理员AppData中的文件夹,而不会删除所有其他用户的文件夹。

有没有办法在批处理,Powershell或最终在VBS中进行?

我的操作系统是Windows 7 x64

1 个答案:

答案 0 :(得分:1)

在PowerShell中:

Remove-Item 'C:\Users\*\AppData\Local\test' -Recurse -Force

在VBScript中:

Set fso = CreateObject("Scripting.FileSystemObject")
For Each sf In fso.GetFolder("C:\Users").SubFolders
  f = fso.BuildPath(sf.Path, "AppData\Local\test")
  If fso.FolderExists(f) Then fso.DeleteFolder f, True
Next

批处理:

for /d %d in (C:\users) do @if exists "%d\AppData\Local\test" rd /s /q "%d\AppData\Local\test"
相关问题