1

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!

1
  • 1
    As in dir c:\directory1\*.txt /s ? Commented May 29, 2013 at 13:54

2 Answers 2

3
for /f "delims=" %%F in ('dir \*.txt /s /b') do copy "%%~F" "c:\test\" /Y
Sign up to request clarification or add additional context in comments.

3 Comments

I tried using what you put and it returned with an error saying "%%F was unexpected at this time".
@jpriff If running from the command line, use single % signs, double %% percent signs are for batch files.
@DavidRuhmann was messing around with it just before commented and saw that the error disappeared with the single %. I am now having an issue with actually copying the files over. It seems to be reading them from the first directory fine, but it wont actually copy anything over. It says total files listed: my\directory\path` then 0 files copied`.
1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.