好的,我有一个文件夹,如下所示
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
最佳答案
恐怕您的要求令人困惑,所以我这样改写了规范:
有几个文件具有这种文件名格式:
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
如果这不是您想要的,请在您的描述中更清楚。
关于windows - 查找批处理的所有重复分钟变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35790608/