Solved

Copy one file to multiple directories w/ batch file

Posted on 2013-02-07
5
827 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

I have published numerous articles here at Experts Exchange that present programs/scripts written in a language called AutoHotkey. Each of those articles has a brief paragraph describing where to download the product and how to install it. I have al…
If you get continual lockouts after changing your Active Directory password, there are several possible reasons.  Two of the most common are using other devices to access your email and stored passwords in the credential manager of windows.
This Micro Tutorial will teach you how to the overview of Microsoft Security Essentials. This is a free anti-virus software that guards your PC against viruses, spyware, worms, and other malicious software. This will be demonstrated using Windows…
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…

757 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

19 Experts available now in Live!

Get 1:1 Help Now