通过批处理文件删除

时间:2013-04-29 19:28:37

标签: batch-file delete-file

我想创建一个批处理文件,通过自动脚本删除网络中的以下路径。

到目前为止,我正在使用:

REM <start>
@echo off
rmdir /s /q c:\users\%allusersprofile%\ppTemp\
REM <end>

每个用户%alluserprofiles%的位置,ppTemp是需要删除的目录。

上面的代码不起作用。

帮助!

1 个答案:

答案 0 :(得分:1)

环境变量引用%AllUsersProfile%会返回一个完全限定的路径,因此在 rmdir 命令中使用C:\users\作为前缀是多余的。它还返回所有用户的程序数据存储路径,而不是单个用户;从你的问题中不清楚你想要的行为。

例如,我在echo %AllUsersProfile%看到的结果是

    Windows 7上的
  • C:\ProgramData
  • Windows XP上的
  • C:\Documents and Settings\All Users

对于 UserProfile 环境变量,echo %UserProfile%返回

  • on Win7:C:\Users\MyUserName
  • on WinXP:C:\Documents and Settings\MyUserName

因此,假设您使用的是Windows 7或Vista,您可能希望将 rmdir 命令更改为:

rmdir /s /q "%UserProfile%\ppTemp\"

应解析为C:\Users\username\ppTemp\

的路径