Board logo

标题: [日期时间] 请教批处理如何加个时间处理删除文件? [打印本页]

作者: gywl110    时间: 2021-7-30 10:27     标题: 请教批处理如何加个时间处理删除文件?

如果写成查找Image文件夹下的20天前的文件,如果都是连同目录一起删除
Image下会有2021-5  2021-6等多个文件夹
  1. @echo off
  2. REM 通过注册表获取微信缓存路径
  3. for /f "tokens=2*" %%i in ('reg query "HKEY_CURRENT_USER\Software\Tencent\WeChat" /v FileSavePath') do (
  4.     set "MyPath=%%j"
  5. )
  6. if /i "%MyPath%" equ "MyDocument:" (
  7. set "WeChatFolder=%userprofile%\Documents"
  8. ) else (
  9.     set "WeChatFolder=%MyPath%"
  10. )
  11. if not exist "%WeChatFolder%" (
  12.     goto :eof
  13. )
  14. REM 清理 Image 文件夹
  15. for /f "delims=" %%i in ('dir /b /s /ad "%WeChatFolder%\WeChat Files\" ^| findstr "\\FileStorage\\Image$"') do (
  16.     pushd "%%i"
  17.     echo 正在处理图片缓存 "%%i"
  18.     for /d %%j in (*) do (
  19.         rd /s /q "%%j"
  20.     )
  21.     popd
  22. )
  23. pause
复制代码

作者: qixiaobin0715    时间: 2021-7-30 10:33

http://bbs.bathome.net/thread-3334-1-1.html
作者: qixiaobin0715    时间: 2021-7-30 10:38

用forfiles
https://docs.microsoft.com/zh-cn ... s-commands/forfiles
作者: gywl110    时间: 2021-7-30 10:39

回复 2# qixiaobin0715 我用【方案3-1】 forfiles 在删除那里改成有点问题
作者: Batcher    时间: 2021-7-30 17:00

回复 4# gywl110


    有点什么问题?
作者: gywl110    时间: 2021-8-2 11:55

本帖最后由 gywl110 于 2021-8-2 12:01 编辑

回复 5# Batcher   把 rd /s /q "%%j"改成forfiles /p 变量目录 /s /m *.* /d -20 /c "cmd /c echo del /f /q /a @path" 请问变量目录应该写成哪一个




欢迎光临 批处理之家 (http://www.bathome.net/) Powered by Discuz! 7.2