1
set path="D:\Work,D:\workin,D:\files"
set files ="txt,html,xml"

How to search for files with an extension defined in files in the directories defined in path and write their names into a file?

Here is what I have tried already:

set "list=list.txt"
pause

pushd "%~dp0"
>"%list%" (
for /f "delims=" %%i in ('2^>nul dir /ad /b') do (
    pushd "%%i"
    for /f "delims=" %%j in ('2^>nul dir /a-d /b *.txt *.html') do (
        echo %%j& >nul 2>&1 copy/y "%%j" ..
    )
    popd
)
)
popd
Mofi
  • 46,139
  • 17
  • 80
  • 143
Vaaassaa
  • 29
  • 1
  • 7
  • Anything you tried so far? – U Rogel Dec 01 '17 at 16:20
  • Start your batch file coding task with reading [Why is no string output with 'echo %var%' after using 'set var = text' on command line?](https://stackoverflow.com/a/26388460/3074564) and with reading [What is the reason for '…' is not recognized as an internal or external command, operable program or batch file?](https://stackoverflow.com/a/41461002/3074564) and you know what you have made already wrong in the first two posted lines. – Mofi Dec 01 '17 at 16:26
  • I highly suggest you never name a variable `PATH`. It is already a system variable and now you have changed it for that session which may cause some of your commands to not run correctly. – Squashman Dec 01 '17 at 16:42

1 Answers1

1

You should be able to simplify this process by using a standard FOR command.

@Echo off

>"FileList.log" (
for %%G in (D:\Work,D:\workin,D:\files) do (
    pushd "%%~G"
    for %%H in (*.xml *.txt *.html) do (
        echo %%~H
        copy /y "%%~H" ..
    )
    popd
)
)
Squashman
  • 13,649
  • 5
  • 27
  • 36