windows - 查找批处理的所有重复分钟变量

标签 windows batch-file

好的,我有一个文件夹,如下所示

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

我阅读了 QGREP 命令,但它也需要一个常量。据我了解。 Image of the times i would like the .bat to find

最佳答案

恐怕您的要求令人困惑,所以我这样改写了规范:

有几个文件具有这种文件名格式:

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/

相关文章:

java - 在 perl 脚本中执行批处理文件时需要提供参数的帮助

mongodb - 将数据从 SQL Server 2008 导入到 mongoDB 数据库(失败的批处理脚本尝试)

java - 在 Windows 上线程直到 Thread.join() 才停止

windows - 处理 nmake 错误级别/返回码

windows - 批处理文件的奇怪行为

python - django操作系统错误: no library called "cairo" was found on windows

batch-file - 在命令提示符中显示 VBS 变量

windows - Powershell相当于cp -n,即复制文件而不覆盖

windows - Delphi - 托盘图标中的文本

c# - Exchange Online 管理 Powershell 模块和证书 Oauth