Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Copying files from multiple directories into a sin  (Read 2252 times)

0 Members and 1 Guest are viewing this topic.

Henryv

  • Guest
Copying files from multiple directories into a sin
« on: July 07, 2006, 01:41:50 PM »
Hello All;

I am trying to create a batch file that will copy files from multiple directories into a single directory using wildcard. Example: I have a directory structure of c:\root\1111, c:\root\2222, c:\root\3333. I would like to copy c:\root\1111\*.txt, c:\root\2222\*.txt, c:\root\3333\*.txt to c:\newdir, and the next time I run it I may have a c:\root\4444, so I need to wild card the directory names as well. Of course the problem is if I use /S and xcopy I get the directory structure recreated, and if I don't I can't traverse the other directories.

Copy c:\root\*\*.txt c:\newdir is what I want but don't have.

I hope this is understanable and thaks in advance for any insight.

Sidewinder



    Guru

    Thanked: 139
  • Experience: Familiar
  • OS: Windows 10
Re: Copying files from multiple directories into a
« Reply #1 on: July 07, 2006, 04:37:53 PM »
If I understand this correctly, you want to traverse the directory structure on the input side, but on the output side all the files end up in the same directory. This may help:

Code: [Select]
@echo off
for /f "tokens=* delims=" %%x in ('dir /a:-d /s /b c:\root\*\*.txt') do (
      copy "%%x" c:\newdir
      )

Good luck.
The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein