日期:2014-05-17 浏览次数:21184 次
@echo off
setlocal enabledelayedexpansion
cd ./log/
cls
set count=0
rem find dirs begin with 20
for /f "delims=" %%m in ('dir /ad /o-d^|findstr "^20"') do (
set dirs=%%m
//这里这样做是因为好像有其他的信息被加入循环了
set dirstr=!dirs:~0,2!
if !dirstr! equ 20 (
set /a count+=1
echo count !count!
if !count! gtr 10 (rd /s /q %%m)
)
)
------解决方案--------------------
你的需求就是保留10个日期较新的文件夹,其它的都删掉?
要是这样的话,你这个写得有点累赘了。你的要求看起来比较复杂,实则处理起来很简单的。
你的每一行都没有发挥出来最佳效果,没利用足,而且也不需要利用count的。
如果你的要求是我说的这样,给你写了一个,代码看下面,你相信就这么简单么,呵呵。
@echo off
cd .\log
cls
for /f "tokens=1* delims=:" %%a in ('dir /b /ad /o-d^|findstr /n ".*"') do (
if %%a gtr 10 (rd /s /q "%%b")
)