?
Solved

Copy file script

Posted on 2011-02-15
13
Medium Priority
?
970 Views
Last Modified: 2012-05-11
I need to create to scripts iin a classroom. Both scripts are essentially the same. I need to copy a config file from 1 pc to a location on 20 other pc's. I just wanted to know if I have to copy from source to destination for each pc or if I can have 1 copy from source to multiple destinations. Any ideas would be great.
0
Comment
Question by:j8547
  • 5
  • 4
  • 2
  • +2
13 Comments
 
LVL 86

Expert Comment

by:oBdA
ID: 34899657
There are several possibilities to run this in a more or less simple script for all machine.
Easiest one: create a file with the names of the 20 "other" PCs (one name per line), for example MachineFile.txt.
Then run something like this in a command prompt in the directory with the list:
for /f "delims=" %a in ('type "MachineList.txt"') do copy "C:\Source\file.txt" "\\%a\C$\Target\Location

If you want to save this as a batch script, double up on the percebt signs:
for /f "delims=" %%a in ('type "MachineList.txt"') do copy "C:\Source\file.txt" "\\%%a\C$\Target\Location

There are other possibilities as well. Do the "other" PCs have a consistent, numeric, naming convention (pc01, pc02, ..., pc20)?
0
 
LVL 19

Expert Comment

by:Thommy
ID: 34899658
You have to call copy for each destination pc by UNC names with hostnames or ips...

copy config.txt \\pc01\c$\configDir\config.txt
...
copy config.txt \\pc20\c$\configDir\config.txt


You can also use ip address:

copy config.txt \\192.168.65.1\c$\configDir\config.txt
...
copy config.txt \\192.168.65.20\c$\configDir\config.txt


0
 

Author Comment

by:j8547
ID: 34899696
I can't use IP address but the pc names range from ...b1 to ...b20

I will try themn out now
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
LVL 86

Expert Comment

by:oBdA
ID: 34899747
With these names, you don't even need a machine list. Just use
for /L %i in (1, 1, 20) do copy "C:\Source\file.txt" "\\...b%i\C$\Target\Location
0
 

Author Comment

by:j8547
ID: 34900014
I am getting the system cannot find the path specified yet the paths look correct. Any ideas???
0
 
LVL 86

Accepted Solution

by:
oBdA earned 2000 total points
ID: 34900080
The closing quotes in the target folder are missing, that could be the issue.
Otherwise, please copy and paste the output of
for /L %i in (1, 1, 20) do @ECHO copy "C:\Source\file.txt" "\\...b%i\C$\Target\Location"
0
 
LVL 83

Expert Comment

by:leakim971
ID: 34900166
You may create a share folder in the main server, create a file with the twenty computer names and use psexec : http://technet.microsoft.com/en-us/sysinternals/bb896649
to run a copy from all the computer to get the file(s) from the main server.
0
 
LVL 83

Expert Comment

by:leakim971
ID: 34900201
0
 
LVL 3

Expert Comment

by:symmcom
ID: 34900235
Assuming you are the administrator and trying to copy the file from the Server to your 20 client computers, simplest form would be:
1. Create a Batch file (anyname.bat)
2. Inside the Batch file type - copy SourceDrive\Thefile.xyz \\ClientPCName\c$\Folder
3. Copy paste this command 19 other times and change the ClientPCName to correct name

This should copy the file to all destination.
0
 

Author Comment

by:j8547
ID: 34901285
It was the quotes. Thanks it is working perfectly now.
0
 

Author Comment

by:j8547
ID: 34901292
Sorry also does the person have to be an admin or can this script use an admin account?????
0
 
LVL 86

Expert Comment

by:oBdA
ID: 34901415
Currently, it has to be an admin due to the administrative share.
If you want this to be run by a regular user, it's safest to share the target folder (with Full Access share permissions for Everyone), and give the "copy" user Change permissions on the target folder.
0
 

Author Comment

by:j8547
ID: 34901422
Thanks
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

601 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