批处理文件“For /f”循环每个文件夹两次,并列出两次文件。

时间:2023-01-25 02:06:59

This for loop loops through the files twice. why is it so? How can I modify this so that each .sql file is listed only once.

这个for循环在文件中循环两次。为什么如此?如何修改它,使每个.sql文件只列出一次。

For /f %%G in ('dir /s /b "%ScriptsPath%" *.sql') do (
    echo "%%G"
) 

2 个解决方案

#1


5  

The dir command is getting confused with the "*.sql" as a separate argument. Try this instead. This code assumes that your ScriptsPath variable does end in a backslash.

dir命令与"* "混淆。sql"作为一个单独的参数。试试这个。此代码假设您的ScriptsPath变量以反斜杠结束。

For /f %%G in ('dir /s /b "%ScriptsPath%*.sql"') do (
    echo "%%G"
) 

#2


0  

It should be like this

应该是这样的

    For /f %%G in ('dir /s /on /b "%ScriptsPath%\*.sql"') do (
    echo "%%G"
    )

I had to add an additional "\" to the path

我必须在路径上添加一个“\”。

Anyways Thanks Luke Z..You made my day!

不管怎样谢谢卢克Z . .你今天真让我高兴!

Thanks & Regards Vinayak

谢谢和问候Vinayak

#1


5  

The dir command is getting confused with the "*.sql" as a separate argument. Try this instead. This code assumes that your ScriptsPath variable does end in a backslash.

dir命令与"* "混淆。sql"作为一个单独的参数。试试这个。此代码假设您的ScriptsPath变量以反斜杠结束。

For /f %%G in ('dir /s /b "%ScriptsPath%*.sql"') do (
    echo "%%G"
) 

#2


0  

It should be like this

应该是这样的

    For /f %%G in ('dir /s /on /b "%ScriptsPath%\*.sql"') do (
    echo "%%G"
    )

I had to add an additional "\" to the path

我必须在路径上添加一个“\”。

Anyways Thanks Luke Z..You made my day!

不管怎样谢谢卢克Z . .你今天真让我高兴!

Thanks & Regards Vinayak

谢谢和问候Vinayak