Solved

Copy one file to multiple directories w/ batch file

Posted on 2013-02-07
5
831 Views
Last Modified: 2013-02-07
Greetings Experts.  I have a spreadsheet that needs to be copied to a set of top level folders but not the sub-folders.  Having most of my experience in scripting coming from batch files, please aim your response in that direction.

file A needs to go to folders A-Z:

FolderA [yes]
--sub folderA [no]
Folder B [yes]
--sub folderB [no]

I asked a similar question before on here but can't find it nor the solution.  I appreciate your time and help with this one!!
0
Comment
Question by:samiam41
  • 2
  • 2
5 Comments
 
LVL 23

Expert Comment

by:Thomas Grassi
ID: 38864051
@echo off
CD \
cd \to folder where your spreadsheet is
copy  spreadsheet.xls c:\foldera\spreadsheet.xls
copy  spreadsheet.xls c:\folderb\spreadsheet.xlscopy  spreadsheet.xls c:\folderc\spreadsheet.xls
etc
etc
etc
copy  spreadsheet.xls c:\folderz\spreadsheet.xls
EXIT
0
 
LVL 1

Accepted Solution

by:
lharrison26 earned 500 total points
ID: 38864091
example:

Need K:\NewCustomers\NewPartNumber.Bat to go into K:\NewCustomers\Customer Name\
 but not any subfolder of \Customer Name\, there being 200-300 "Customer Name" folders.

Answer:

Using for /d to loop through folders in a non-recursive fashion is the way to go

for /d %%a in ("K:\NewCustomers\*") do copy "K:\NewCustomers\NewPartNumber.bat" "%%a"

 Alternatively, you can use a for /f loop in combination with dir:

@echo off
pushd "K:\NewCustomers"
for /f "tokens=*" %%a in ('dir /A:D /B') do copy "NewPartNumber.bat" "%%a"
popd

 Personally, I prefer the first method more, though.
0
 
LVL 9

Author Comment

by:samiam41
ID: 38864193
Thanks Experts.  Testing now.
0
 
LVL 9

Author Closing Comment

by:samiam41
ID: 38864226
One line of code and the task was finished.  I appreciate everyone's help and look forward to working with you all again soon.  Thanks.
0
 
LVL 1

Expert Comment

by:lharrison26
ID: 38864252
Glad to help.
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

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…
A quick guide on how to use Group Policy to create a custom power plan and set it active on Windows 7.
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
The viewer will learn how to successfully download and install the SARDU utility on Windows 7, without downloading adware.

773 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