Windows 批量匹配一个字符串

Windows Batch matching a string

最后我想匹配一个字符串并使用那个值。

我的计算机上的不同位置有很多名为 TEST123456 且编号不同的文件夹。 使用 dir TEST?????? /s /b /a:d > folders.txt 我可以获得一个类似于以下内容的文件:

C:/folder1/folder2/TEST123456
C:/folder1/folder2/TEST654321
C:/folder2/TEST246810

现在这个列表会很大,所以我想按数字排序。我想将此文件更改为:

TEST123456C:/folder1/folder2/TEST123456
TEST654321C:/folder1/folder2/TEST654321
TEST246810C:/folder2/TEST246810

在文本文件中插入行时最好但不是必须这样做。

现在我尝试使用 findstr TEST...... folders.txt 但它会打印整行,而我只需要匹配的字符串。我是 Windows Batch 的初学者,所以我认为创建我想要的东西应该相对容易。

您可以使用 FOR /D 循环浏览文件夹:

@echo off
>folders.txt (
for /D /R %%A in (test??????) do echo %%~nxA%%A
)