Share via

How to search file recursively in for do loop in a bat file

Fanhua Kong 241 Reputation points
Apr 23, 2023, 1:56 AM

Hi guys. I'm using a bat file to process a large amount of files. The script I used was as below:

for %%f in ("%~dp0*.dwg") do accoreconsole.exe /i "%%f" /s "C:\Users\MiralKong\Desktop\TEST\ExtendDataTest.scr"

It worked fine except that it only searched the folder which the bat file was in. How could I search all the sub folders recursively in this circumstance? As far as I know the "dir /s/b *.dwg" would list all the match files. However how could it be nested in the for do loop? Thanks in advance.

Windows 11
Windows 11
A Microsoft operating system designed for productivity, creativity, and ease of use.
11,341 questions
0 comments No comments
{count} votes

Accepted answer
  1. MotoX80 35,626 Reputation points
    Apr 23, 2023, 3:21 PM

    Use Powershell.

    Get-ChildItem -Filter *.dwg -recurse  | foreach {
        accoreconsole.exe /i "$($_.fullname)" /s "C:\Users\MiralKong\Desktop\TEST\ExtendDataTest.scr"
    }
    

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.