Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Copy one file to multiple directories w/ batch file

Posted on 2013-02-07
5
Medium Priority
?
840 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

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.
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…
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…
Suggested Courses

705 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