删除批处理文件中的临时文件

发布于 2024-07-16 13:48:48 字数 7981 浏览 10 评论 0原文

只是构建一个批处理文件来删除我的 vista 机器@ home 上的临时文件,我想将其添加到任务计划程序中。 到目前为止,我已经做到了这一点,但我遇到了很多访问被拒绝的情况,而且它从未找到thumbs.db 文件或index.dat,而且有很多。 我究竟做错了什么?

 attrib +a -s -h -r "%windir%\Temp\*.*" /s
  del /f /s /q "%windir%\Temp\*.*" >>"logs\temp.txt"

 attrib +a -s -h -r "thumbs.db" /s
  del /s /f /q "thumbs.db" >>"logs\temp.txt"

 attrib +a -s -h -r *.tmp.log /s
  del /s /f /q "*.tmp.log" >>"logs\temp.txt"

 attrib +a -s -h -r “%userprofile%\Application Data\Microsoft\Office\Recent\*.*” /s
  del /f /q /s “%userprofile%\Application Data\Microsoft\Office\Recent\*.*” >>"logs\temp.txt"

 attrib +a -s -h -r "%systemdrive%\*.gid" /s
  del /s /f / q "%systemdrive%\*.gid" >>"logs\temp.txt"

 attrib +a -s -h -r "%systemdrive%\*.fts" /s
  del /s /f /q "%systemdrive%\*.fts" >>"logs\temp.txt"

 attrib +a -s -h -r "%systemdrive%\*.cnt" /s
  del /s /f /q "%systemdrive%\*.cnt" >>"logs\temp.txt"

 attrib +a -s -h -r "%systemdrive%\*.old" /s
  del /s /f /q "%systemdrive%\*.old" >>"logs\temp.txt"

 attrib +a -s -h -r "%systemdrive%\*.diz" /s
  del /s /f /q "%systemdrive%\*.diz" >>"logs\temp.txt"

 attrib +a -s -h -r "%systemdrive%\*.bak" /s
  del /s /f /q "%systemdrive%\*.bak" >>"logs\temp.txt"

 attrib +a -s -h -r "%systemdrive%\*.tmp" /s
  del /s /f /q "%systemdrive%\*.tmp" >>"logs\temp.txt"

 attrib +a -s -h -r "%systemdrive%\*.chk" /s
  del /s /f /q "%systemdrive%\*.chk" >>"logs\temp.txt"

 attrib +a -s -h -r "%systemdrive%\*.dmp" /s
  del /s /f /q "%systemdrive%\*.dmp" >>"logs\temp.txt"

 attrib +a -s -h -r "%systemdrive%\*.00?" /s
  del /s /f /q "%systemdrive%\*.00?" >>"logs\temp.txt"

 attrib +a -s -h -r "%systemdrive%\index.dat" /s
  del /s /f /q "%systemdrive%\index.dat" >>"logs\temp.txt"

 attrib +a -s -h -r "%systemdrive%\fw*log.txt" /s
  del /s /f /q "%systemdrive%\fw*log.txt" >>"logs\temp.txt"

 attrib +a -s -h -r "%systemdrive%\zalog*.txt" /s
  del /s /f /q "%systemdrive%\zalog*.txt" >>"logs\temp.txt"

 attrib +a -s -h -r "%systemdrive%\backup*.rdb" /s
  del /s /f /q "%systemdrive%\backup*.rdb" >>"logs\temp.txt"

 attrib +a -s -h -r "%systemdrive%\*._mp" /s  
  del /f /s /q %systemdrive%\*._mp >>"logs\temp.txt"

 attrib +a -s -h -r "%systemdrive%\*.log" /s 
  del /f /s /q "%systemdrive%\*.log" >>"logs\temp.txt"

 attrib +a -s -h -r "%systemdrive%\Temp\*.*" /s
  del /f /s /q "%systemdrive%\Temp\*.*" >>"logs\temp.txt"

 attrib +a -s -h -r "%systemdrive%\Users\Default\AppData\Local\Microsoft\Windows\History\*.*" /s
  del /f /s /q "%systemdrive%\Users\Default\AppData\Local\Microsoft\Windows\History\*.*" >>"logs\temp.txt"

 attrib +a -s -h -r "%systemdrive%\Users\Default\AppData\Local\Microsoft\Windows\Temporary Internet Files\*.*" /s
  del /f /s /q "%systemdrive%\Users\Default\AppData\Local\Microsoft\Windows\Temporary Internet Files\*.*" >>"logs\temp.txt"

 attrib +a -s -h -r "%systemdrive%\Users\Default\AppData\Local\Temp\*.*" /s
  del /f /s /q "%systemdrive%\Users\Default\AppData\Local\Temp\*.*" >>"logs\temp.txt"

 attrib +a -s -h -r "%systemdrive%\Users\Default\AppData\Roaming\Microsoft\Windows\Cookies\*.*" /s
  del /f /s /q "%systemdrive%\Users\Default\AppData\Roaming\Microsoft\Windows\Cookies\*.*" >>"logs\temp.txt"

 attrib +a -s -h -r "%systemdrive%\Users\Default\AppData\Roaming\Microsoft\Windows\Recent\*.*" /s
  del /f /s /q "%systemdrive%\Users\Default\AppData\Roaming\Microsoft\Windows\Recent\*.*" >>"logs\temp.txt"

 attrib +a -s -h -r "%systemdrive%\Windows\Downloaded Program Files\*.*" /s
  del /f /s /q "%systemdrive%\Windows\Downloaded Program Files\*.*" >>"logs\temp.txt"

 attrib +a -s -h -r "%ProgramData%\Apple\Installer Cache\*.*" /s 
  del /f /s /q "%ProgramData%\Apple\Installer Cache\*.*" >>"logs\temp.txt"

 attrib +a -s -h -r "%ProgramData%\Apple Computer\Installer Cache\*.*" /s
  del /f /s /q "%ProgramData%\Apple Computer\Installer Cache\*.*" >>"logs\temp.txt"

 attrib +a -s -h -r "%ProgramData%\Microsoft\Search\Data\Temp\*.*" /s
  del /f /s /q "%ProgramData%\Microsoft\Search\Data\Temp\*.*" >>"logs\temp.txt"

 attrib +a -s -h -r "%ProgramData%\Temp\*.*" /s
  del /f /s /q "%ProgramData%\Temp\*.*" >>"logs\temp.txt"

 attrib +a -s -h -r "%appdata%\Adobe\Flash Player\AssetCache\*.*" /s
  del /f /s /q "%appdata%\Adobe\Flash Player\AssetCache\*.*" >>"logs\temp.txt"

 attrib +a -s -h -r "%appdata%\Macromedia\Flash Player\#SharedObjects\*.*" /s
  del /f /s /q "%appdata%\Macromedia\Flash Player\#SharedObjects\*.*" >>"logs\temp.txt"

 attrib +a -s -h -r "%appdata%\Macromedia\Flash Player\macromedia.com\support\flashplayer\sys\*.*" /s
  del /f /s /q "%appdata%\Macromedia\Flash Player\macromedia.com\support\flashplayer\sys\*.*" >>"logs\temp.txt"

 attrib +a -s -h -r "%appdata%\Macromedia\Flash Player\macromedia.com\support\flashplayer\sys\*.*" /s
  del /f /s /q "%appdata%\Macromedia\Flash Player\macromedia.com\support\flashplayer\sys\*.*" >>"logs\temp.txt"

 attrib +a -s -h -r "%appdata%\Microsoft\Windows\Cookies\*.*" /s
  del /f /s /q "%appdata%\Microsoft\Windows\Cookies\*.*" >>"logs\temp.txt"

 attrib +a -s -h -r "%appdata%\Microsoft\Windows\Recent\*.*" /s
  del /f /s /q "%appdata%\Microsoft\Windows\Recent\*.*" >>"logs\temp.txt"

 attrib +a -s -h -r "%appdata%\Mozilla\Firefox\Crash Reports\*.*" /s
  del /f /s /q "%appdata%\Mozilla\Firefox\Crash Reports\*.*" >>"logs\temp.txt"

 attrib +a -s -h -r "%appdata%\Sun\Java\Deployment\cache*.*" /s
  del /f /s /q "%appdata%\Sun\Java\Deployment\cache*.*" >>"logs\temp.txt"

 attrib +a -s -h -r "%appdata%\uTorrent\*.*" /s
  del /f /s /q "%appdata%\uTorrent\*.*" >>"logs\temp.txt"

 attrib +a -s -h -r "%userprofile%\AppData\Local\Temp" /s
  del /f /s /q "%userprofile%\AppData\Local\Temp" >>"logs\temp.txt"

 attrib +a -s -h -r "%userprofile%\AppData\LocalLow\Temp" /s
  del /f /s /q "%userprofile%\AppData\LocalLow\Temp" >>"logs\temp.txt"

 attrib +a -s -h -r "%userprofile%\AppData\Local\Microsoft\Windows Photo Gallery\Original Images\*.*" /s 
  del /f /s /q "%userprofile%\AppData\Local\Microsoft\Windows Photo Gallery\original Images\*.*" >>"logs\temp.txt"

 attrib +a -s -h -r "%userprofile%\AppData\Local\Microsoft\Windows\Burn\*.*" /s 
  del /f /s /q "%userprofile%\AppData\Local\Microsoft\Windows\Burn\*.*" >>"logs\temp.txt"

 attrib +a -s -h -r "%userprofile%\AppData\Local\Microsoft\Windows\Explorer\*.*" /s 
  del /f /s /q "%userprofile%\AppData\Local\Microsoft\Windows\Explorer\*.*" >>"logs\temp.txt"

 attrib +a -s -h -r "%userprofile%\AppData\Local\Microsoft\Windows\History\*.*" /s 
  del /f /s /q "%userprofile%\AppData\Local\Microsoft\Windows\History\*.*" >>"logs\temp.txt"

 attrib +a -s -h -r "%userprofile%\AppData\Local\Microsoft\Windows\Temporary Internet Files\*.*" /s 
  del /f /s /q "%userprofile%\AppData\Local\Microsoft\Windows\Temporary Internet Files\*.*" >>"logs\temp.txt"

 attrib +a -s -h -r "%userprofile%\AppData\Local\Mozilla\Firefox\Profiles\*\Cache\*.*" /s
  del /f /s /q "%userprofile%\AppData\Local\Mozilla\Firefox\Profiles\*\Cache\*.*" >>"logs\temp.txt"

 attrib +a -s -h -r "%userprofile%\AppData\Local\Microsoft\Windows\Explorer\*.db" /s
  del /f /s /q "%userprofile%\AppData\Local\Microsoft\Windows\Explorer\*.db" >>"logs\temp.txt"

 attrib +a -s -h -r "%appdata%\Microsoft\Windows\cookies\*.*" /s
  del /f /s /q "%appdata%\Microsoft\Windows\cookies\*.*"  >>"logs\temp.txt"

 attrib +a -s -h -r "%appdata%\Microsoft\Windows\Recent\*.*" /s
  del /f /s /q "%appdata%\Microsoft\Windows\Recent\*.*" >>"logs\temp.txt"

 attrib +a -s -h -r "%windir%\prefetch\*.*" /s
  del /f /s /q "%windir%\prefetch\*.*" >>"logs\temp.txt"

 attrib +a -s -h -r "%windir%\SoftwareDistribution\Download\*.*" /s
  del /f /s /q "%windir%\SoftwareDistribution\Download\*.*" >>"logs\temp.txt"

Just building a batch file to delete temp files on my vista machines @ home that I want to add to task scheduler. I have this so far, but I get a lot of access denied, and it never finds a thumbs.db file or index.dat and there are heaps of them. What am I doing wrong?

 attrib +a -s -h -r "%windir%\Temp\*.*" /s
  del /f /s /q "%windir%\Temp\*.*" >>"logs\temp.txt"

 attrib +a -s -h -r "thumbs.db" /s
  del /s /f /q "thumbs.db" >>"logs\temp.txt"

 attrib +a -s -h -r *.tmp.log /s
  del /s /f /q "*.tmp.log" >>"logs\temp.txt"

 attrib +a -s -h -r “%userprofile%\Application Data\Microsoft\Office\Recent\*.*” /s
  del /f /q /s “%userprofile%\Application Data\Microsoft\Office\Recent\*.*” >>"logs\temp.txt"

 attrib +a -s -h -r "%systemdrive%\*.gid" /s
  del /s /f / q "%systemdrive%\*.gid" >>"logs\temp.txt"

 attrib +a -s -h -r "%systemdrive%\*.fts" /s
  del /s /f /q "%systemdrive%\*.fts" >>"logs\temp.txt"

 attrib +a -s -h -r "%systemdrive%\*.cnt" /s
  del /s /f /q "%systemdrive%\*.cnt" >>"logs\temp.txt"

 attrib +a -s -h -r "%systemdrive%\*.old" /s
  del /s /f /q "%systemdrive%\*.old" >>"logs\temp.txt"

 attrib +a -s -h -r "%systemdrive%\*.diz" /s
  del /s /f /q "%systemdrive%\*.diz" >>"logs\temp.txt"

 attrib +a -s -h -r "%systemdrive%\*.bak" /s
  del /s /f /q "%systemdrive%\*.bak" >>"logs\temp.txt"

 attrib +a -s -h -r "%systemdrive%\*.tmp" /s
  del /s /f /q "%systemdrive%\*.tmp" >>"logs\temp.txt"

 attrib +a -s -h -r "%systemdrive%\*.chk" /s
  del /s /f /q "%systemdrive%\*.chk" >>"logs\temp.txt"

 attrib +a -s -h -r "%systemdrive%\*.dmp" /s
  del /s /f /q "%systemdrive%\*.dmp" >>"logs\temp.txt"

 attrib +a -s -h -r "%systemdrive%\*.00?" /s
  del /s /f /q "%systemdrive%\*.00?" >>"logs\temp.txt"

 attrib +a -s -h -r "%systemdrive%\index.dat" /s
  del /s /f /q "%systemdrive%\index.dat" >>"logs\temp.txt"

 attrib +a -s -h -r "%systemdrive%\fw*log.txt" /s
  del /s /f /q "%systemdrive%\fw*log.txt" >>"logs\temp.txt"

 attrib +a -s -h -r "%systemdrive%\zalog*.txt" /s
  del /s /f /q "%systemdrive%\zalog*.txt" >>"logs\temp.txt"

 attrib +a -s -h -r "%systemdrive%\backup*.rdb" /s
  del /s /f /q "%systemdrive%\backup*.rdb" >>"logs\temp.txt"

 attrib +a -s -h -r "%systemdrive%\*._mp" /s  
  del /f /s /q %systemdrive%\*._mp >>"logs\temp.txt"

 attrib +a -s -h -r "%systemdrive%\*.log" /s 
  del /f /s /q "%systemdrive%\*.log" >>"logs\temp.txt"

 attrib +a -s -h -r "%systemdrive%\Temp\*.*" /s
  del /f /s /q "%systemdrive%\Temp\*.*" >>"logs\temp.txt"

 attrib +a -s -h -r "%systemdrive%\Users\Default\AppData\Local\Microsoft\Windows\History\*.*" /s
  del /f /s /q "%systemdrive%\Users\Default\AppData\Local\Microsoft\Windows\History\*.*" >>"logs\temp.txt"

 attrib +a -s -h -r "%systemdrive%\Users\Default\AppData\Local\Microsoft\Windows\Temporary Internet Files\*.*" /s
  del /f /s /q "%systemdrive%\Users\Default\AppData\Local\Microsoft\Windows\Temporary Internet Files\*.*" >>"logs\temp.txt"

 attrib +a -s -h -r "%systemdrive%\Users\Default\AppData\Local\Temp\*.*" /s
  del /f /s /q "%systemdrive%\Users\Default\AppData\Local\Temp\*.*" >>"logs\temp.txt"

 attrib +a -s -h -r "%systemdrive%\Users\Default\AppData\Roaming\Microsoft\Windows\Cookies\*.*" /s
  del /f /s /q "%systemdrive%\Users\Default\AppData\Roaming\Microsoft\Windows\Cookies\*.*" >>"logs\temp.txt"

 attrib +a -s -h -r "%systemdrive%\Users\Default\AppData\Roaming\Microsoft\Windows\Recent\*.*" /s
  del /f /s /q "%systemdrive%\Users\Default\AppData\Roaming\Microsoft\Windows\Recent\*.*" >>"logs\temp.txt"

 attrib +a -s -h -r "%systemdrive%\Windows\Downloaded Program Files\*.*" /s
  del /f /s /q "%systemdrive%\Windows\Downloaded Program Files\*.*" >>"logs\temp.txt"

 attrib +a -s -h -r "%ProgramData%\Apple\Installer Cache\*.*" /s 
  del /f /s /q "%ProgramData%\Apple\Installer Cache\*.*" >>"logs\temp.txt"

 attrib +a -s -h -r "%ProgramData%\Apple Computer\Installer Cache\*.*" /s
  del /f /s /q "%ProgramData%\Apple Computer\Installer Cache\*.*" >>"logs\temp.txt"

 attrib +a -s -h -r "%ProgramData%\Microsoft\Search\Data\Temp\*.*" /s
  del /f /s /q "%ProgramData%\Microsoft\Search\Data\Temp\*.*" >>"logs\temp.txt"

 attrib +a -s -h -r "%ProgramData%\Temp\*.*" /s
  del /f /s /q "%ProgramData%\Temp\*.*" >>"logs\temp.txt"

 attrib +a -s -h -r "%appdata%\Adobe\Flash Player\AssetCache\*.*" /s
  del /f /s /q "%appdata%\Adobe\Flash Player\AssetCache\*.*" >>"logs\temp.txt"

 attrib +a -s -h -r "%appdata%\Macromedia\Flash Player\#SharedObjects\*.*" /s
  del /f /s /q "%appdata%\Macromedia\Flash Player\#SharedObjects\*.*" >>"logs\temp.txt"

 attrib +a -s -h -r "%appdata%\Macromedia\Flash Player\macromedia.com\support\flashplayer\sys\*.*" /s
  del /f /s /q "%appdata%\Macromedia\Flash Player\macromedia.com\support\flashplayer\sys\*.*" >>"logs\temp.txt"

 attrib +a -s -h -r "%appdata%\Macromedia\Flash Player\macromedia.com\support\flashplayer\sys\*.*" /s
  del /f /s /q "%appdata%\Macromedia\Flash Player\macromedia.com\support\flashplayer\sys\*.*" >>"logs\temp.txt"

 attrib +a -s -h -r "%appdata%\Microsoft\Windows\Cookies\*.*" /s
  del /f /s /q "%appdata%\Microsoft\Windows\Cookies\*.*" >>"logs\temp.txt"

 attrib +a -s -h -r "%appdata%\Microsoft\Windows\Recent\*.*" /s
  del /f /s /q "%appdata%\Microsoft\Windows\Recent\*.*" >>"logs\temp.txt"

 attrib +a -s -h -r "%appdata%\Mozilla\Firefox\Crash Reports\*.*" /s
  del /f /s /q "%appdata%\Mozilla\Firefox\Crash Reports\*.*" >>"logs\temp.txt"

 attrib +a -s -h -r "%appdata%\Sun\Java\Deployment\cache*.*" /s
  del /f /s /q "%appdata%\Sun\Java\Deployment\cache*.*" >>"logs\temp.txt"

 attrib +a -s -h -r "%appdata%\uTorrent\*.*" /s
  del /f /s /q "%appdata%\uTorrent\*.*" >>"logs\temp.txt"

 attrib +a -s -h -r "%userprofile%\AppData\Local\Temp" /s
  del /f /s /q "%userprofile%\AppData\Local\Temp" >>"logs\temp.txt"

 attrib +a -s -h -r "%userprofile%\AppData\LocalLow\Temp" /s
  del /f /s /q "%userprofile%\AppData\LocalLow\Temp" >>"logs\temp.txt"

 attrib +a -s -h -r "%userprofile%\AppData\Local\Microsoft\Windows Photo Gallery\Original Images\*.*" /s 
  del /f /s /q "%userprofile%\AppData\Local\Microsoft\Windows Photo Gallery\original Images\*.*" >>"logs\temp.txt"

 attrib +a -s -h -r "%userprofile%\AppData\Local\Microsoft\Windows\Burn\*.*" /s 
  del /f /s /q "%userprofile%\AppData\Local\Microsoft\Windows\Burn\*.*" >>"logs\temp.txt"

 attrib +a -s -h -r "%userprofile%\AppData\Local\Microsoft\Windows\Explorer\*.*" /s 
  del /f /s /q "%userprofile%\AppData\Local\Microsoft\Windows\Explorer\*.*" >>"logs\temp.txt"

 attrib +a -s -h -r "%userprofile%\AppData\Local\Microsoft\Windows\History\*.*" /s 
  del /f /s /q "%userprofile%\AppData\Local\Microsoft\Windows\History\*.*" >>"logs\temp.txt"

 attrib +a -s -h -r "%userprofile%\AppData\Local\Microsoft\Windows\Temporary Internet Files\*.*" /s 
  del /f /s /q "%userprofile%\AppData\Local\Microsoft\Windows\Temporary Internet Files\*.*" >>"logs\temp.txt"

 attrib +a -s -h -r "%userprofile%\AppData\Local\Mozilla\Firefox\Profiles\*\Cache\*.*" /s
  del /f /s /q "%userprofile%\AppData\Local\Mozilla\Firefox\Profiles\*\Cache\*.*" >>"logs\temp.txt"

 attrib +a -s -h -r "%userprofile%\AppData\Local\Microsoft\Windows\Explorer\*.db" /s
  del /f /s /q "%userprofile%\AppData\Local\Microsoft\Windows\Explorer\*.db" >>"logs\temp.txt"

 attrib +a -s -h -r "%appdata%\Microsoft\Windows\cookies\*.*" /s
  del /f /s /q "%appdata%\Microsoft\Windows\cookies\*.*"  >>"logs\temp.txt"

 attrib +a -s -h -r "%appdata%\Microsoft\Windows\Recent\*.*" /s
  del /f /s /q "%appdata%\Microsoft\Windows\Recent\*.*" >>"logs\temp.txt"

 attrib +a -s -h -r "%windir%\prefetch\*.*" /s
  del /f /s /q "%windir%\prefetch\*.*" >>"logs\temp.txt"

 attrib +a -s -h -r "%windir%\SoftwareDistribution\Download\*.*" /s
  del /f /s /q "%windir%\SoftwareDistribution\Download\*.*" >>"logs\temp.txt"

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

红ご颜醉 2024-07-23 13:48:48

您是否记得在设置新属性和删除时设置目标文件夹?

以下是针对网络删除拇指文件的示例:

attrib +a -s -h -r \\your-sample-network-path\thumbs.db /s
del /s /f /q \\your-sample-network-path\thumbs.db

Did you remember to set the target folder when setting new attributes and deleting?

Here is a sample for deleting thumbs files, targeting network:

attrib +a -s -h -r \\your-sample-network-path\thumbs.db /s
del /s /f /q \\your-sample-network-path\thumbs.db
寻找一个思念的角度 2024-07-23 13:48:48

我猜测您访问被拒绝的原因是运行脚本的用户没有相关文件的删除权限,甚至没有文件夹的访问权限。

至于thumbs.db和index.dat文件,它们是隐藏文件和/或系统文件,因此不会被普通的删除命令拾取。 您需要使用 /A:H 和/或 /A:S

I'm guessing that the reason you're getting access denied is because the user running the script doesn't have delete rights to the files in question or perhaps even access rights to the folders.

As for the thumbs.db and index.dat files, these are hidden and/or system files so won't get picked up by the plain delete command. You need to use /A:H and/or /A:S

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文