繁体   English   中英

如何基于一个列表文件从一个文件夹到下一个文件夹搜索文件直到找到

[英]How to search files from one folder to next till found based upon a list file in batch

我正在寻找一个批处理文件来执行以下任务:

1)在此文件中有一个列表文件,例如list.txt:

12345.S3S
12346.S3S
12347.S3S
12348.S3S
12349.S3S

2)现在,我想使用批处理文件来进行从一个文件夹到另一个文件夹的搜索,直到找到为止。 否则说没有搜索

folder1/ maybe only have 4 files
folder2  maybe only have 4 files
folder3  have all 5 files

因此,仅搜索folder3并输出文件以列出这5个文件的所有路径...

  • 预计将首先展示您自己的编码工作。
  • 以下批处理使用一组固定的文件夹/文件进行演示-也可以动态收集。
  • 提供的文件夹名称和文件名称均不包含空格:

@Echo off&SetLocal EnableExtensions EnableDelayedExpansion

Set "Folders=folder1 folder2 folder3"
Set "Files=12345.S3S 12346.S3S 12347.S3S 12348.S3S 12349.S3S"

CD /D "X:\Base\path"

For %%A in (%Folders%) Do (
    Set Cnt=0
    For %%B in (%Files%) Do (
        If Exist "%%A\%%B" Set /A Cnt+=1
    )
    If !Cnt!==5 (Set "Found=%%A"&Goto :Success)
)
Echo Fail couldn't find a folder with all file
Pause
Goto :Eof

:Success
Echo Found all of (%Files%) in %Found%
Pause
Goto :Eof

样品运行:

> tree . /F
A:\
├───folder1
│       12345.S3S
│       12347.S3S
│       12348.S3S
│       12349.S3S
├───folder2
│       12345.S3S
│       12346.S3S
│       12347.S3S
│       12349.S3S
└───folder3
        12345.S3S
        12346.S3S
        12347.S3S
        12348.S3S
        12349.S3S


> Q:\Test\2017\08\22\SO_45825229.cmd
Found all of (12345.S3S 12346.S3S 12347.S3S 12348.S3S 12349.S3S) in folder3

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM