scapegoat17
scapegoat17

Reputation: 5821

Finding files in multiple directories using CMD

I am trying to figure out the best way to find all the files listed in specific directories. This is my issue:

In Directory1 there are a bunch of directories like SubDir1, SubDir2, SubDir3, etc... I need to find all the .txt files in the sub directories while being in Directory1 with one command all at once. I am assuming it would be some kind of wildcard operator that would do the trick but I have also been known to be wrong in the past...

EDIT:

Knowing that:

dir \*.txt /s

would access all of the files, what would be the best way to copy all of them to a folder called "test" the same way?

Thank you!

Upvotes: 1

Views: 865

Answers (2)

npocmaka
npocmaka

Reputation: 57262

for /f "delims=" %%F in ('dir \*.txt /s /b') do copy "%%~F" "c:\test\" /Y

Upvotes: 3

scapegoat17
scapegoat17

Reputation: 5821

Thanks to @npocmaka and @DavidRuhmann this is what worked for me:

for /f "delims=" %F in ('dir \*.txt /s/b') do copy "%~F" "C:\test\" /Y

Upvotes: 1

Related Questions