[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖
太厉害了!
我需要一个能删除指定目录(包括子目录)下特定日期文件的批处理,和帖子里的批处理相比,多了递归子目录文件的需求。请版主劳神写一个。谢谢了!

TOP

回复 81# 一坑坑兔一


    把*.*改成*.bat
我帮忙写的代码不需要付钱。如果一定要给,请在微信群或QQ群发给大家吧。
【微信公众号、微信群、QQ群】http://bbs.bathome.net/thread-3473-1-1.html
【支持批处理之家,加入VIP会员!】http://bbs.bathome.net/thread-67716-1-1.html

TOP

大神,还在吗?看了你的批处理的帖子收获很大,我想问一下,我现在想做一个删除7天之前的指定路径下的文件夹的bat文件,详细代码应该怎么写?http://bbs.bathome.net/thread-3334-1-1.html这个帖子里都是删除文件的,在线等,急用,谢谢。系统是xp,最好做一个通用的。win7—xp

TOP

系统时间回到了 2002.1.1   电池坏了

TOP

回复 78# forfiles


    还是十分感谢。

TOP

回复 77# 喃喃努努


    我手上没有NT系统,无法测试。

TOP

回复 76# forfiles


    谢谢,在xp运行也是ok的,就是NT系统不能嵌套,郁闷。

TOP

回复 75# 喃喃努努


我在Win7里面测试了一下没有问题:
  1. set SrcDir=D:\temp1
  2. for /f "skip=3 tokens=1,3,*" %%a in ('dir %SrcDir%\*.* /tw /od') do (
  3.     if "1" LEQ "2" (
  4.         echo right %%a %%c
  5.     ) else (
  6.         echo wrong %%a %%c
  7.     )
  8. )
  9. pause
复制代码

TOP

回复 72# forfiles


    我这里没有做实际的时间比较,因为时间格式还没有统一,所以你先帮我看看为什么for和if嵌套不行,也没报错,只是没有运行结果;for单独运行可以,if单独运行也可以,就是for和if 嵌套没有运行结果。

TOP

回复 72# forfiles


D:\WINNT\Profiles\ASEKS\Desktop>set SrcDir=D:\temp1

D:\WINNT\Profiles\ASEKS\Desktop>set DaysAgo=1

D:\WINNT\Profiles\ASEKS\Desktop>echo Set WshShell = WScript.CreateObject("WScript.Shell"
) 1>"D:\TEMP\BackupDate.vbs"

D:\WINNT\Profiles\ASEKS\Desktop>echo WScript.Echo WshShell.RegRead ("HKEY_CURRENT_USER\C
ontrol Panel\International\sShortDate") 1>>"D:\TEMP\BackupDate.vbs"

D:\WINNT\Profiles\ASEKS\Desktop>FOR /F %a in ('cscript /nologo "D:\TEMP\BackupDate.vbs"'
) do (set "RegDateOld=%a" )

D:\WINNT\Profiles\ASEKS\Desktop>(set "RegDateOld=yyyy-M-d" )

D:\WINNT\Profiles\ASEKS\Desktop>pause
Press any key to continue . . .

D:\WINNT\Profiles\ASEKS\Desktop>echo Set WshShell = WScript.CreateObject("WScript.Shell"
) 1>"D:\TEMP\UnifyDate.vbs"

D:\WINNT\Profiles\ASEKS\Desktop>echo WshShell.RegWrite "HKEY_CURRENT_USER\Control Panel\
International\sShortDate", "yyyy-M-d", "REG_SZ" 1>>"D:\TEMP\UnifyDate.vbs"

D:\WINNT\Profiles\ASEKS\Desktop>cscript /nologo "D:\TEMP\UnifyDate.vbs"

D:\WINNT\Profiles\ASEKS\Desktop>echo LastDate=date()-1 1>"D:\TEMP\DstDate.vbs"

D:\WINNT\Profiles\ASEKS\Desktop>echo FmtDate=right(year(LastDate),4) & right("0" & month
(LastDate),2) & right("0" & day(LastDate),2) 1>>"D:\TEMP\DstDate.vbs"

D:\WINNT\Profiles\ASEKS\Desktop>echo wscript.echo FmtDate 1>>"D:\TEMP\DstDate.vbs"

D:\WINNT\Profiles\ASEKS\Desktop>FOR /F %a in ('cscript /nologo "D:\TEMP\DstDate.vbs"') d
o (set "DstDate=%a" )

D:\WINNT\Profiles\ASEKS\Desktop>(set "DstDate=20120902" )

D:\WINNT\Profiles\ASEKS\Desktop>set DstDate=2012-09-02

D:\WINNT\Profiles\ASEKS\Desktop>pause
Press any key to continue . . .
D:\WINNT\Profiles\ASEKS\Desktop>dir D:\temp1\*.* /tw /od /tw
Volume in drive D is WINNT
Volume Serial Number is 642B-B607

Directory of D:\temp1

08/28/12  04:24p                32,700 fldb1897
08/29/12  03:40p                32,704 fldb1898
08/31/12  02:42a                54,117 fldb1913
09/01/12  01:26a                54,121 fldb1916
09/03/12  01:26p                     0 TEST.txt
09/03/12  01:26p        <DIR>          ..
09/03/12  01:26p        <DIR>          .
               7 File(s)        173,642 bytes
                          1,073,503,744 bytes free

D:\WINNT\Profiles\ASEKS\Desktop>pause
Press any key to continue . . .

D:\WINNT\Profiles\ASEKS\Desktop>FOR /F "skip=3 tokens=1,3,*" %a in ('dir D:\temp1\*.* /t
w /od') do (echo %a %c )

D:\WINNT\Profiles\ASEKS\Desktop>(echo Directory  )
Directory

D:\WINNT\Profiles\ASEKS\Desktop>(echo 08/28/12 fldb1897 )
08/28/12 fldb1897

D:\WINNT\Profiles\ASEKS\Desktop>(echo 08/29/12 fldb1898 )
08/29/12 fldb1898

D:\WINNT\Profiles\ASEKS\Desktop>(echo 08/31/12 fldb1913 )
08/31/12 fldb1913

D:\WINNT\Profiles\ASEKS\Desktop>(echo 09/01/12 fldb1916 )
09/01/12 fldb1916

D:\WINNT\Profiles\ASEKS\Desktop>(echo 09/03/12 TEST.txt )
09/03/12 TEST.txt

D:\WINNT\Profiles\ASEKS\Desktop>(echo 09/03/12 .. )
09/03/12 ..

D:\WINNT\Profiles\ASEKS\Desktop>(echo 09/03/12 . )
09/03/12 .

D:\WINNT\Profiles\ASEKS\Desktop>(echo 7 bytes )
7 bytes

D:\WINNT\Profiles\ASEKS\Desktop>(echo 1,073,503,744  )
1,073,503,744

D:\WINNT\Profiles\ASEKS\Desktop>pause
Press any key to continue . . .

D:\WINNT\Profiles\ASEKS\Desktop>if "1" LEQ "2" echo  del /f /q 123
del /f /q 123

D:\WINNT\Profiles\ASEKS\Desktop>if "3" LEQ "2" echo  del /f /q 456

D:\WINNT\Profiles\ASEKS\Desktop>pause
Press any key to continue . . .

D:\WINNT\Profiles\ASEKS\Desktop>FOR /F "skip=3 tokens=1,3,*" %a in ('dir D:\temp1\*.* /t
w /od') do (if "1" LEQ "2" (echo  %a %c ) )

D:\WINNT\Profiles\ASEKS\Desktop>pause
Press any key to continue . . .

D:\WINNT\Profiles\ASEKS\Desktop>echo Set WshShell = WScript.CreateObject("WScript.Shell"
) 1>"D:\TEMP\RecoverDate.vbs"

D:\WINNT\Profiles\ASEKS\Desktop>echo WshShell.RegWrite "HKEY_CURRENT_USER\Control Panel\
International\sShortDate", "yyyy-M-d", "REG_SZ" 1>>"D:\TEMP\RecoverDate.vbs"

D:\WINNT\Profiles\ASEKS\Desktop>cscript /nologo "D:\TEMP\RecoverDate.vbs"

D:\WINNT\Profiles\ASEKS\Desktop>pause
Press any key to continue . . .

TOP

回复 72# forfiles
  1. set SrcDir=D:\temp1
  2. set DaysAgo=1
  3. >"%temp%\BackupDate.vbs" echo Set WshShell = WScript.CreateObject("WScript.Shell")
  4. >>"%temp%\BackupDate.vbs" echo WScript.Echo WshShell.RegRead ("HKEY_CURRENT_USER\Control
  5. Panel\International\sShortDate")
  6. for /f %%a in ('cscript /nologo "%temp%\BackupDate.vbs"') do (
  7.     set "RegDateOld=%%a"
  8. )
  9. pause
  10. >"%temp%\UnifyDate.vbs" echo Set WshShell = WScript.CreateObject("WScript.Shell")
  11. >>"%temp%\UnifyDate.vbs" echo WshShell.RegWrite "HKEY_CURRENT_USER\Control
  12. Panel\International\sShortDate", "yyyy-M-d", "REG_SZ"
  13. cscript /nologo "%temp%\UnifyDate.vbs"
  14. >"%temp%\DstDate.vbs" echo LastDate=date()-%DaysAgo%
  15. >>"%temp%\DstDate.vbs" echo FmtDate=right(year(LastDate),4) ^& right("0" ^&
  16. month(LastDate),2) ^& right("0" ^& day(LastDate),2)
  17. >>"%temp%\DstDate.vbs" echo wscript.echo FmtDate
  18. for /f %%a in ('cscript /nologo "%temp%\DstDate.vbs"') do (
  19.     set "DstDate=%%a"
  20. )
  21. set DstDate=%DstDate:~0,4%-%DstDate:~4,2%-%DstDate:~6,2%
  22. pause
  23. dir %SrcDir%\*.* /tw /od /tw
  24. pause
  25. for /f "skip=3 tokens=1,3,*" %%a in ('dir %SrcDir%\*.* /tw /od') do (echo %%a %%c)
  26. pause
  27. if "1" LEQ "2" echo  del /f /q 123
  28. if "3" LEQ "2" echo  del /f /q 456
  29. pause
  30. for /f "skip=3 tokens=1,3,*" %%a in ('dir %SrcDir%\*.* /tw /od') do (
  31.     if "1" LEQ "2" (
  32.           echo  %%a %%c
  33.     )
  34. )
  35. pause
  36. >"%temp%\RecoverDate.vbs" echo Set WshShell = WScript.CreateObject("WScript.Shell")
  37. >>"%temp%\RecoverDate.vbs" echo WshShell.RegWrite "HKEY_CURRENT_USER\Control
  38. Panel\International\sShortDate", "%RegDateOld%", "REG_SZ"
  39. cscript /nologo "%temp%\RecoverDate.vbs"
  40. pause
复制代码

TOP

回复 71# 喃喃努努


把你的完整代码贴出来我看看
还有就是把@echo off删掉执行一遍把过程贴出来

TOP

回复 68# forfiles


    突然发现可以NT系统可以if判断比较,也可以for循环,但是两个不能嵌套,嵌套在一起的话不运行直接跳过,也不报错,不知道什么情况。

TOP

回复 68# forfiles


这个是NT的注册表里面的,好像时间格式和我们需要的yyyy-M-d一样,但是用dir显示出来的为什么还是m/d/yy,搞不懂。

TOP

回复 68# forfiles


不行啊,reg好像在NT系统里面用不了。只能找其他出路了。

TOP

返回列表