-1

I want to copy all .txt files which might be in sub folders or under main folder(source) to destination main folder

i.e E:\source\sub1\sub11 or E:\source\sub2 or E:\source\ to d:\test folder.

Here i want to copy only .txt files not there subfolder to destination folder.

I have tired many options suggested in this forum .I am unable to ignore sub folders.

Suppose i have .txt file in E:\source\sub1\sub11 when tired to copy.txt file to destination folder then hierarchy in destination folder will be d:\test folder\sub1\sub11

here i want to copy to main folder d:\test folder not d:\test folder\sub1\sub11

Please can any one help me here

Thanks in advance

akappa
  • 10,220
  • 3
  • 39
  • 56
  • Assuming this is windows cmd you want to use, and not C++ as you suggest in the tags? Also, what commands have you tried? – Chris May 28 '12 at 11:38
  • changed tag to windows-shell, since C++ has nothing to relate to his question – akappa May 28 '12 at 12:02
  • What do you expect to happen if 2 different versions of `file.txt` exist in 2 source sub-folders? Only one version can exist in your destination folder. – dbenham May 28 '12 at 12:41
  • Which is it? Do you want to copy *.h or *.txt? – dbenham May 28 '12 at 17:15
  • .h files below command working fine for me. – user1421582 May 29 '12 at 04:29
  • I am new to this forum.pardon me if my question looks very simple for you guys.I am doing embedded testing on one of the project.When there are so many dependency problems related to .h files.so i have posted this question here. – user1421582 May 29 '12 at 04:35

1 Answers1

0

You can use the FOR command to copy recursively each file individually:

for /r e:\source %a in (*.txt) do @copy "%a" "d:\test folder\"

(You need to use %%a instead of %a if the command is inside a batch file).

alexisdm
  • 29,448
  • 6
  • 64
  • 99
  • Perhaps should use *.h instead of *.txt, that is if the OP can figure out what the requirements really are. – dbenham May 28 '12 at 17:15
  • I had tired this command.with different option.But didn't work might be i was using wrong formae.Thank you for your valuable input on this topic – user1421582 May 29 '12 at 04:25