Link to home
Start Free TrialLog in
Avatar of MartinP1969
MartinP1969Flag for United Kingdom of Great Britain and Northern Ireland

asked on

Script that copies a single file to numerous computers

Hi Techies
I recently had to manually copy a file from a server share to 30 pc;s, I'm sure there must be an automated script I could run. The details are:-

Copy a single file, which will be the same every time from a UNC server path to different desktop machines, the path will always be the same for the desktops.


Is there a batch file or some kind of script I could run which would prompt for the path of the server, then enter filename.

From here if you could then say take input from a text file with the name of all the machines needs copying to, and the path to these machines which is always the same.

There may already be a script out there that does this or I can modify to suit?

If there is any flexibility in selecting filename or paths, maybe a browse dialog box, then even better


Please assist


Mart
Avatar of mfsamuel
mfsamuel

try a batch file with something like this...
(stolen from code to search directories from a serverlist.txt file)
serverlist.txt contains
server,path  
e.g.
server3,e$\dept
-----------
The server list has the folders you are copy to, and the original file is hard coded.  easy to change this if you need more functionality.  save it as copyfiles.bat (or something similar)
@echo off
set servlist=c:\serverlist.txt
if not exist %servlist% echo %servlist% not found & pause & goto end
for /f "tokens=1,2*" %%a in (%servlist%) do call :process %%a %%b
goto end
:process
COPY C:\testfile.txt \\%1\%2
:end 

Open in new window

try this sub routine...

sub copystuff(byval ComputerName)
      strhere = "c:\download_file_abc.txt"      'copy from
      strthere = "\\" & ComputerName & "\c$\Folders\download_file_abc.txt"    'copy to
      Set fso = CreateObject("Scripting.FileSystemObject")
      fso.CopyFile strhere, strthere,TRUE
end sub
ASKER CERTIFIED SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The script will prompt the following answer
Pc list[leave empty for AUTOMATIC/file]? =   if empty the list will be automatically generated
File to be copied? =     absolute path to the file UNC or local
Destination directory? =  is the share on every pc
and  then start to copying...

Bye Gas
::
:: capy-all.cmd
:: copy a file in all pc
::  
::     
:: gastone canali  
:: 
@ECHO off
SETLOCAL EnableDelayedExpansion
cls
echo.
set /p pclist=Pc list[leave empty for AUTOMATIC/file]? =
set computers=type "%pclist%"
if not exist "%pclist%"  echo "Computer list automatically generated"   
if not exist "%pclist%"  set computers=net view^^^|find /i "\\"
echo.
echo  File Ex.: \\server1\accounting\read me.txt
set /p file=File to be copied? =
if not exist "%file%" goto :_ERR
echo Source file: %file%
echo.
echo  Destination directory Ex.: temp
set /p dest=Destination directory?
echo.
echo The file %file% will be copied on all \\pc\%dest%
echo.&pause
for  /f "delims=\" %%c in ('%computers%') do call :_DO %%c 
goto :_END
 
:_DO
set cmd=copy /y "%file%" "\\%1\%dest%"
set alive=yes
ping -n 1 -4 -w 300 %1 |find /i "ttl" >nul || set alive=no
if +!alive!+==+no+  ( 
   echo %1 --- switched 0ff 
) else (
   %cmd% 2>nul|find /i "0 file" >nul  && echo Failed to copy in "\\%1\%dest%" ||echo Successfully copied in "\\%1\%dest%" 
)
goto :_EOF
:_ERR
 echo error! File not found...
goto :_EOF
 
:_END
:_EOF

Open in new window

Avatar of MartinP1969

ASKER

Sorry for the delay, some personal stuff kicking off.

I would like to award the points to Rob Sampson, whose answer fit the bill the most and was slick and informative

I have upped the points from 200 to 300, as I would like to extend it a little bit and the points are yours Rob

1 Appears only can select from C:, not any folders or subfolders?

2 Can you include it for network drive selection vias the GUI

3 Possible to select the destination of the file via GUI to include network frives and folders? or at least locally, not relying on hard coded destination


I would like to thank you all for your efforts, you make IT happen
Will respond quickly if get the little amenmemts

Thanks Again

Mart
Thanks Rob, quality answer, if you have the time, please see my last comments, you may be able to tweak it a bit. I award all points, plus bonus points  up front as gesture.

Thanks to all who contributed

Cheers

Mart
Hey Mart, sorry for my late reply.  Thanks for the grade by the way.

For your questions 1 and 2, on my system, I can select any network drive from the top of the dialog, and any subfolder....so I'm not sure why you are unable to.


For question 3, unfortunately, no. VBScript does have a "folder picker" implementation of the dialog.  It can only select individual files.  You could, however, have the destination entered as a text string by the user by changing this line:
strDestinationLocal = "C:\Temp"

to this:
strDestinationLocal = InputBox("Enter the destination path:", "Destination Folder", "C:\Temp")

Regards,

Rob.