中国DOS联盟

-- 联合DOS 推动DOS 发展DOS --

联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum
DOS,代表着自由开放与发展,我们努力起来,学习FreeDOS和Linux的自由开放与GNU精神,共同创造和发展美好的自由与GNU GPL世界吧!

中国DOS联盟论坛
现在时间是 2026-08-09 14:40
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Findstr的问题 查看 748 回复 1
楼 主 Findstr的问题 发表于 2008-09-04 16:34 ·  中国 台湾 台北市 远传电信
初级用户
积分 107
发帖 42
注册 2007-09-03 16:43
18年会员
UID 96475
性别 男
状态 离线
这里写了一个用Findstr搭配dir来找在从当月开始算起往前三个月之内,在一些固定资料夹中将exe com档案列出并显示修改日期以及档案大小

但到最后的Findstr 要找exe com的时候最后就没有列出任何东西
不知道最后面的Findstr能不能这样用?

代码如下:


@if not defined debug @echo off
@prompt $
set system=%systemroot%\system32

if exist C_File.dat del C_File.dat /Q
if not exist Time_B.reg regedit /e /a "Time_B.reg" "HKEY_CURRENT_USER\Control Panel\International"

@(
echo REGEDIT4
echo
echo "iDate"="2"
echo "iMeasure"="0"
echo "iTime"="1"
echo "iTLZero"="1"
echo "sDate"="-"
echo "sLongDate"="yyyy-MM-dd"
echo "sShortDate"="yyyy-MM-dd"
echo "sTimeFormat"="HH:mm"
echo "iCountry"="1"
echo "iDigits"="2"
echo "iLZero"="1"
echo "sDecimal"="."
echo "sThousand"=","
echo "sTime"=":"
)> Time_A.reg

regedit /s "Time_A.reg"
del Time_A.reg /Q

set "year_t=%date:~0,4%"
set "month_t=%date:~5,2%"
echo %month_t% | Findstr "0." >nul && set month_t=%month_t:~1,1%

:: 1 month
set /a month_1=%month_t%-1
set /a year_1=%year_t%
if %month_1% EQU 0 (
set /a year_1=%year_1%-1
set /a month_1=12
)

:: 2 month
set /a month_2=%month_1%-1
set /a year_2=%year_1%
if %month_2% EQU 0 (
set /a year_2=%year_2%-1
set /a month_2=12
)

:: 3 month
set /a month_3=%month_2%-1
set /a year_3=%year_2%
if %month_3% EQU 0 (
set /a year_3=%year_3%-1
set /a month_3=12
)

if %month_1% LSS 10 set month_1=0%month_1%
if %month_2% LSS 10 set month_2=0%month_2%
if %month_3% LSS 10 set month_3=0%month_3%

set "Today=^%year_t%-%month_t%"
set "1month=^%year_1%-%month_1%"
set "2month=^%year_2%-%month_2%"
set "3month=^%year_3%-%month_3%"

call :C_File %systemroot%
call :C_File %system%
if defined Temp call :C_File %temp%
goto end

:C_File
for /f "tokens=1,3,*" %%a in (
'dir /tc /a-d "%~1\*" ^| Findstr "%today% %1month% %2month% %3month%"'
) do for /f "tokens=*" %%g in ('echo %~1\%%c') do echo %%a . %%~tg %%~zg %%~g >> C_File.dat
goto:eof

:end
Findstr -i "\.exe$ \.com$" C_File.dat

del C_File.dat /Q
regedit /s "Time_B.reg"
@prompt $P$G



最后面的Findstr如果改成
Findstr -i "\.exe \.com" C_File.dat 就可以正常显示
但这样只要中间字符有.exe和.com的也一样会显示出来

请问有没有什么方式可以修正的?

[ Last edited by sylovanas on 2008-9-4 at 06:01 PM ]
2 发表于 2008-09-04 18:35 ·  中国 江苏 苏州 中移铁通
银牌会员
★★★
积分 1,608
发帖 780
注册 2007-10-07 10:19
18年会员
UID 99089
性别 男
状态 离线
findstr/ic:""
论坛跳转: