Can forfiles search multiple drives in the same command and create a text file of results? I have the following that works to show me the results in command prompt but what I really need is a .txt file that displays all the matches.

Also, if there was a way of searching C:\ and D:\ in the same instance?

forfiles /p c:\ /s /m XYZ*.* /d -15 /c "cmd /c echo @file is a txt file and older then 15 days

I have adjusted the line so that it outputs a text file in the folder that command prompt is opening from so that part is done but I am still trying to figure out how to scan the C: and the D: in the same command. The new line is:

forfiles /p c:\ /s /m XYZ*.* /d -15 /c "cmd /c echo @path" >outputC.txt

1 Answer 1


I created a .bat file with the following text and it gave me what I was hoping to accomplish:

forfiles /p c:\ /s /m *XYZ*.* /d -15 /c "cmd /c echo @path" >outputC.txt

forfiles /p d:\ /s /m *XYZ*.* /d -15 /c "cmd /c echo @path" >outputD.txt

Separating the lines with the enter key created the two separate text output files.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .