Please help! I an new to creating batch files.

I am trying to create a batch file to do the following things :

  1. Search for file(s) with a certain file extension (i.e. .docx) within a folder
  2. Output both filename(s) and extension to a text file (.txt)
  3. In the text file, I want to add an index before the file name

For example, "folder 1" has these three files : test1.docx, test2.docx, test3.xlsx The batch file will search for these three files that have extension with .docx, and then output to a text file (i.e. search_result.txt)

In the search_result.txt, it will have this format :

1 test1.docx
2 test2.docx

here is what I have so far which is doing #1 and #2 items mentioned above, but I need help to implement #3.

@echo off
for /r %%i in (*.docx) do echo %%~nxi >> search_result.txt

Thank you in advance for the help.

Edit
Report