Solved

copy files from multiple subdirectories to one

Posted on 2007-04-05
5
600 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 82

Expert Comment

by:oBdA
Comment Utility
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
Comment Utility
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
Comment Utility
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 82

Accepted Solution

by:
oBdA earned 250 total points
Comment Utility
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
Comment Utility
that worked perfectly. thank you
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
Learn about cloud computing and its benefits for small business owners.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now