批处理脚本,用于列出选定的.xml,名称中包含日期,文件名为.txt文件

批处理脚本,用于列出选定的.xml,名称中包含日期,文件名为.txt文件,xml,batch-file,batch-processing,Xml,Batch File,Batch Processing,提前感谢你的帮助 我有一些xml文件在文件夹中的文件名中包含日期 范例 Profile-20131126-1.xml Profile-20131125-2.xml Profile-20131124-5.xml Logic145242013_11_26.xml Logic154752013_11_25.xml Logic154852013_11_24.xml 现在我需要将2013年11月26日之前的文件名保存到一个.txt文件中。日期可以在文件名中看到 因此,输出应该如下所示 Profile

提前感谢你的帮助

我有一些xml文件在文件夹中的文件名中包含日期

范例

  • Profile-20131126-1.xml
  • Profile-20131125-2.xml
  • Profile-20131124-5.xml
  • Logic145242013_11_26.xml
  • Logic154752013_11_25.xml
  • Logic154852013_11_24.xml
现在我需要将2013年11月26日之前的文件名保存到一个.txt文件中。日期可以在文件名中看到

因此,输出应该如下所示

  • Profile-20131125-2.xml
  • Profile-20131124-5.xml
  • Logic154752013_11_25.xml
  • Logic154852013_11_24.xml
有人能帮我看一下批处理脚本吗

感谢和问候,
Siva

除了将问题分为两部分之外,我看不到其他解决方案: 对于Profile-*.xml文件 对于逻辑*.xml文件

在下面的脚本中,我使用了与20131126的比较来获取较旧的文件。将文件名分成几个部分,以便以上面的格式获取日期,以便进行比较

@echo off
setlocal EnableDelayedExpansion

set mydate=20131126

rem take each file name
for %%a in (Profile-*-*.xml) do (
    rem take only data, split by dash and take second value
    for /F "tokens=2 delims=-" %%f in ("%%a") do (
        rem compare with 20131126
        if %%f LSS %mydate% (   
            echo %%a>>txtfile.txt
            rem Add processing of your files here  
        )
    )
)

rem take each file name
for %%a in (Logic*_*_*.xml) do (     
    rem put the value in a local parameter
    set filename=%%a
    rem take only the last 14 to 4 letters 
    set filename=!filename:~-14,-4!
    rem remove underscores
    set filename=!filename:_=!
    rem compare with 20131126
    if !filename! LSS %mydate% (         
        echo %%a>>txtfile.txt
        rem Add processing of your files here 
    )   
)

这些示例是该目录中唯一的文件结构吗?逻辑文件在日期部分之前总是有5个数字吗?嗨,Mihai,我面临的问题是日期对应于当前日期。例如,今天的日期是2013年11月28日。文件夹中有文件Profile-20131126-1.xml Profile-20131125-2.xml Profile-20131124-5.xml Profile-20131127-5.xml Logic145242013_11_27.xml Logic154752013_11_25.xml。在这种情况下,只有以下文件应输入到.txt文件中。Profile-20131126-1.xml Profile-20131125-2.xml Profile-20131124-5.xml逻辑154752013_11_25.xml。我的意思是说比今天少的部分应该是outputHi湿婆。请从代码中删除注释,或者像我编辑的那样放入其他行。在原始问题中,您要求输出中包含日期小于2013年11月26日的文件。您可以将当前日期作为参数传递给脚本,也可以自动获取它,但这可能很棘手。