Solved

copy files from multiple subdirectories to one

Posted on 2007-04-05
5
607 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 84

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 84

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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Suggested Solutions

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…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

733 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