Solved

copy files from multiple subdirectories to one

Posted on 2007-04-05
5
604 Views
Last Modified: 2010-04-16
I thought I asked this the other day but something must have happened. I need to write a batch file script that will copy certain file types (*.doc for instance) from multiple subdirectories to another location. For instance:

Copy *.doc from c:\myfiles\all sub directories\*certain criteria*.doc to D:\permanent location

xcopy seems to always want to create the directory structure and subdirectories and i just want the files. Can someone point me in the right direction?
0
Comment
Question by:CUBLA1
  • 3
  • 2
5 Comments
 
LVL 83

Expert Comment

by:oBdA
ID: 18860436
Try this; note the "/L" as argument for xcopy, which will only list the files it would copy otherwise, so that you can test it. Add other arguments as required.

@echo off
for /r "c:\myfiles\all sub directories" %%a in ("*certain criteria*.doc") do xcopy "%%a" "D:\permanent location\" /L
0
 

Author Comment

by:CUBLA1
ID: 18860546
Ok I receive the same result from when I tried your exact same solution after reading the FOR command instructions...and I just can't figure it out. I get:

Site"\Transcribers" was unexpected at this time

Now my source path is D:\FTP Site\Transcribers

The FTP has a space after it / before Site and I think this is causing problems but we cannot change it?
0
 

Author Comment

by:CUBLA1
ID: 18860557
This is what I have in my test.bat file:

@echo off
for /R "D:\"FTP Site"\Transcribers" %%a in (*LEC*.DOC) do xcopy "%%a" "D:\"FTP Site"\Dictators\LEC\#PENDING\" /L
0
 
LVL 83

Accepted Solution

by:
oBdA earned 250 total points
ID: 18861570
No need to add quotes all over the place; they're only necessary around the complete path.

@echo off
for /r "D:\FTP Site\Transcribers" %%a in ("*LEC*.DOC") do xcopy "%%a" "D:\FTP Site\Dictators\LEC\#PENDING\" /L
0
 

Author Comment

by:CUBLA1
ID: 18883516
that worked perfectly. thank you
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
Issue: One Windows 2008 R2 64bit server on the network unable to connect to a buffalo Device (Linkstation) with firmware version 1.56. There are a total of four servers on the network this being one of them. Troubleshooting Steps: Connect via h…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question