好的,我有一个文件夹,如下面的
ERROR WITH Position Post_20162602_022046.eml
ERROR WITH Position Post_20162602_032048.eml
ERROR WITH Position Post_20162602_042050.eml
ERROR WITH Position Post_20162602_052108.eml
ERROR WITH Position Post_20162602_062109.eml
ERROR WITH Position Post_20162602_012110.eml
ERROR WITH Position Post_20162602_012111.eml
ERROR WITH Position Post_20162602_012114.eml
ERROR WITH Position Post_20162602_012121.eml
EXCEPTION ERROR_20162602_034502.eml
EXCEPTION ERROR_20162602_072602.eml
INCOMPLETE MESSAGE_20162602_092345.eml
我的目标是使用.bat文件来查看HH:MM:SS(小时:分钟:秒) 该文件的一部分,并确定在此示例中在01 21处发出的所有电子邮件。然而,var将根据遇到错误的时间而改变,并且程序可能必须搜索不同的时间......
这个问题唯一不变的是文件时间会重复,但我无法知道多少次,多少次或多少次。所以我需要.bat来查看时间是重复的,然后显示所有重复的文件。
我设法在下面找到了这段代码,但它查看了文件扩展名并且有一个常量PATTERN
var
@Echo OFF
Set "Pattern=abcd"
For /R "C:\" %%# in (*.xml) Do (
Echo %%~nx# | FIND "%Pattern%" 1>NUL && (
Set /A "Index+=1"
Call Set "XML%%INDEX%%=%%~#"
Echo Full Path: %%~#
REM Echo FileName : %%~nx#
REM Echo Directory: %%~p#
)
)
CLS
Echo XML1 = %XML1%
Echo XML2 = %XML2%
Pause&Exit
答案 0 :(得分:3)
我担心您的请求令人困惑,所以我用这种方式改写了规范:
有多个文件具有此文件名格式:
Any text_YYYYDDMM_HHMMSS.eml
根据HHMM对文件进行计数,并在计数大于1时报告文件名。
@echo off
setlocal EnableDelayedExpansion
for %%a in (*.eml) do (
for /F "tokens=3 delims=_" %%b in ("%%~Na") do (
set "fileTime=%%b"
for %%t in (!fileTime:~0^,4!) do (
set /A "count[%%t]+=1"
set names[%%t]=!names[%%t]! "%%a"
)
)
)
echo More than 1 message received at:
for /F "tokens=2,3 delims=[]=" %%a in ('set count[') do (
if %%b gtr 1 (
echo ------------------------
for %%c in (!names[%%a]!) do (
echo %%~c
)
)
)
输出示例:
More than 1 message received at:
------------------------
ERROR WITH Position Post_20162602_012110.eml
ERROR WITH Position Post_20162602_012111.eml
ERROR WITH Position Post_20162602_012114.eml
ERROR WITH Position Post_20162602_012121.eml
如果这不是您想要的,请在说明中更清楚。